-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
  • 409
  • 2
  • 12
  • 34

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,601
  • 3
  • 21
  • 49
2
for(i=1*counter, j=a*counter; i<=a*counter && j>=1*counter; i++, j--)
P.P
  • 117,907
  • 20
  • 175
  • 238
kotlomoy
  • 1,420
  • 8
  • 14