Chapter 6

Loops

Often, programs contain blocks of code to be executed more than once. A statement whose job is to repeatedly execute the same block of code as long as the value of a controlling expression is true is called an iteration loop. In this chapter, you’ll learn about C’s iteration statements: for, while, and do-while, which allow us to set up loops, as well as break, continue, and goto statements, which can be used to transfer control from one point of a program to another.

for Statement

for statement is one of C’s three loop statements. It is typically used when the number of iterations is predetermined. The general form of the for statement is:

for(init_exp; cond_exp; update_exp)
{
/* a block of statements (the loop body) that ...

Get C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.