1. ## For loop

Hi!

I have a question about for loops.

I have this:

Code:
```for (i=0; i<5; i++) {
for (k=0; k<4; k++) {
for (l=0; l<6; l++) }
/* some code */
}
}
}```
Is it important the order in the for loops?
Must be the value of the first loop the biggest or the smallest (i<5)?

2. If there are no other instructions in the first and second for statements, the order is not important. In your example, 'some code' is being executed 120 times.

You could simplify this with:

Code:
```for ( i=0; i<120; i++ )
{
/* some code */
}```
However, if there is more code to be handled within these for loops (but outside the third loop), then the order is important.

(I'm assuming the brace after the third for loop is intended to be { and not } ).

3. >Is it important the order in the for loops?
Yes, it's very important. The inner loops must need to be performed in their entirety for each iteration of the loop immediately outside it. So if I needed three loops, A loop must run 4 times, B loop must run three times with each iteration of A loop, and C loop must run 6 times inside B loop I would write this code.
Code:
```for(A = 0; A < 4; ++A){
for(B = 0; B < 3; ++B){
for(C = 0; C < 6; ++C){
/*do stuff*/
}
}
}```

4. ## Re: For loop

Originally posted by GaPe
Must be the value of the first loop the biggest or the smallest (i<5)?

The answer is neither. As long as the expression results in a true condition, the code within the for statement will be executed.

The for statement has four main parts:

Code:
```for ( initilization; test; increment )
{