Leaving Parts Blank in a for loop. (#30479)

pull/32944/head^2
AKASH JAIN 2018-12-17 22:36:38 +05:30 committed by Christopher McCormack
parent 8ac6600a23
commit 4fc41ac133
1 changed files with 5 additions and 1 deletions

View File

@ -16,7 +16,6 @@ for ( initialization; condition; update ) {
statement(s);
}
```
The `for` loop consists of 3 sections:
1. The initialization section (start value)
2. Condition (stop value)
@ -24,6 +23,11 @@ The `for` loop consists of 3 sections:
The initialization statement is executed only once. Then, the condition is evaluated. If the condition is false (0), the `for` loop is terminated. But if the condition is true (nonzero), code inside the block of the `for` loop is executed. Finally, the update expression is executed. This process repeats until the condition is false.
You can leave any of the three field blank:
- If you leave initialization blank, then there is no initialization phase
- If you leave update blank, then there is no update phase
- If you leave the condition blank, then practically it becomes an infinite loop unless you break inside loop
The `for` loop is commonly used when the number of iterations is known.
#### Example