Bifalgorithm post · Computer science one · Do-While Loops
How are for loops structured in C?
How are for loops structured in C? (Computer science one · Do-While Loops) — "For loops in C use the familiar syntax of placing the initialization, continuatio…
Ideas in this flowchart
- For loops in C
- The initialization, continuation condition, and iteration appear on the same line as the for keyword.
- Code Sample 17.3 demonstrates a for loop with i initialized to 1 and continued through 10.
- Semicolons follow the initialization and continuation condition, but not the iteration statement.
- The opening curly bracket shares the for line, and the loop body is indented consistently.
- In the shown convention, the index variable i is declared before the for loop.
- Some languages allow the index variable to be declared in the initialization statement.
- Declaring i in the initialization scopes it to the loop, so it is unavailable before and after the loop body.
- C89 and earlier standards require the variable to be declared before the loop.
- C99 and newer standards allow declaration of the index variable in the initialization statement.
- The older declaration convention is followed for maximum portability.