-3

I need to execute two conditions for i and j simultaneously.

condition for i: for(i=1*counter; i<= len*7*counter; i++)

condition for j: for(j=len*7*counter; j>=1*counter; j--)

And then, when both these conditions are true, i need to execute bin[i-1]=temp[j-1];

What is the correct way of writing this?

Note: This is not a nested loop.

Is this the correct way?

for(i=1*counter && j=a*counter; i<=a*counter && j>=1*counter; i++ && j--)

newbee
  • 389
  • 2
  • 10
  • 33

2 Answers2

6

To execute two conditions you need to separate them by comma (they will execute only once):

for( i = 1*counter, j = a*counter; 

Use logical AND operator in order to "unite" these conditions:

i <= a*counter && j >= 1*counter;

Separate i++ and j-- by comma too:

i++, j-- )

Now, you have exactly what you need:

for( i = 1*counter, j = a*counter; i <= a*counter && j >= 1*counter; i++, j-- )
yulian
  • 1,555
  • 3
  • 20
  • 48
2
for(i=1*counter, j=a*counter; i<=a*counter && j>=1*counter; i++, j--)
P.P
  • 112,354
  • 20
  • 166
  • 226
kotlomoy
  • 1,390
  • 7
  • 13