C Programming For Loop
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Syntax
statement
expression1 initializes a loop count variable once at the start of the loop (e.g. i = 0). expression2 is the test condition – the loop will continue while this is true (e.g. i <= 10). expression3 is executed at the end of each iteration – usually to modify the loop count variable (e.g. i++)
2
3 for (i = 0; i < 5; i++)
4 {
5 printf("Loop iteration %d\n", i);
6 }
The expected output for this for loop is:
Loop iteration 1
Loop iteration 2
Loop iteration 3
Loop iteration 4
It is important to mention that any or all of the three expressions in a for loop may be left blank (semi-colons must remain). If expression1 or expression3 are missing, their actions simply disappear. If expression2 is missing, it is assumed to always be true.