Primary
For Loop ○꠹|Definition|1st|20251119205401-00-⌔
Loop (statement) - Wikipedia#Three-part_for_loop
Three-part for loop
A three-part for loop, popularized by C, has two additional parts: initialization (loop variant), and increment, both of which are blocks of code. The initialization is intended as code that prepares the loop and is run once in the beginning and increment is used to update the state of the program after each iteration of the loop. Otherwise, the three-part for loop is a pre-test loop. They are commonly formatted in manner similar to
for initialization, condition, increment do body repeatThis syntax came from B and was originally invented by Stephen C. Johnson.1 The following C code is an example of a three part loop that prints the numbers from 0 to 4.
for (int i = 0; i < 5; i++) { printf("%d\n", i); }Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original Footnotes
Thompson, Ken. VCF East 2019 – Brian Kernighan interviews Ken Thompson. YouTube. Archived from the original on 2021-12-12. Retrieved 2020-11-16. I saw Johnson’s semicolon version of the for loop and I put that in[B], I stole it. ↩
Secondary
• • •