Introduction to C Programming
Looping Constructs

Computers are very good at performing repetitive tasks very quickly. In this section we will learn how to make computer repeat actions either a specified number of times or until some stopping condition is met.

while Loops ( Condition-Controlled Loops )

while( condition ) body;

where the body can be either a single statement or a block of statements within < curly braces >.

int i = 0; while( i < 5 ) printf( "i = %d\n", i++ ); printf( "After loop, i = %d\n", i );

do-while Loops

do < body; >while( condition );
int month; do < printf( "Please enter the month of your birth >" ); scanf( "%d", &month ); > while ( month < 1 || month >12 );

for Loops

where again the body can be either a single statement or a block of statements within < curly braces >.