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. Show
while Loops ( Condition-Controlled Loops )
while( condition ) body;
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
|