Any of the three clauses of the for loop may be left empty.
If the initialization clause is left empty, no initialization is done before the loop starts executing for the first time.
1
2
3
4
5
| // Loop until i reaches 10, no matter what its starting valuefor (; i <= 10; i++){ Console.WriteLine(i);} |
If the condition clause is empty, no condition is ever checked to determine when the loop should exit and the loop executes forever.
1
2
3
4
5
| // Loop forever, incrementing ifor (int i = 0; ; i++){ Console.WriteLine(i);} |
The iteration clause can also be empty.
1
2
3
4
5
6
7
| // Get 'er done, Herculesfor (int laborNum = 1; laborNum <= 12; ){ bool success = HerculesLabors(laborNum); if (success == true) laborNum++;} |

