September 1998
Intermediate to advanced
848 pages
20h 13m
English
The while loop and the for loop are both entry-condition loops. The test condition is checked before each iteration of the loop, so it is possible for the statements in the loop to never execute. C also has an exit-condition loop in which the condition is checked after each iteration of the loop, guaranteeing that statements are executed at least once. This variety is called a do while loop. Listing 6.13 shows an example.
/* dowhile.c -- exit condition loop */
#include <stdio.h>
int main(void)
{
char ch;
do
{
scanf("%c", &ch);
printf("%c", ch);
} while (ch != '#');
return 0;
}
|
The program in Listing 6.13 reads input characters and reprints them until the # character shows ...
Read now
Unlock full access