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 is ...

Get C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.