Stats

142 Contributors: 10 Wednesday, June 21, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Iteration Statements/Loops: for, while, do-while

Syntax

  • /* all versions */
  • for ([expression]; [expression]; [expression]) one_statement
  • for ([expression]; [expression]; [expression]) { zero or several statements }
  • while (expression) one_statement
  • while (expression) { zero or several statements }
  • do one_statement while (expression);
  • do { one or more statements } while (expression);
  • // since C99 in addition to the form above
  • for (declaration; [expression]; [expression]) one_statement;
  • for (declaration; [expression]; [expression]) { zero or several statements }

Remarks

Iteration Statement/Loops fall into two categories:

  • head-controlled iteration statement/loops
  • foot-controlled iteration statement/loops

Head-Controlled Iteration Statement/Loops

for ([<expression>]; [<expression>]; [<expression>]) <statement>
while (<expression>) <statement>
C99
for ([declaration expression]; [expression] [; [expression]]) statement

Foot-Controlled Iteration Statement/Loops

do <statement> while (<expression>);

Related Examples