September 2001
Beginner
970 pages
23h 20m
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.15 shows an example.
/* dowhile.c -- exit condition loop */ #include <stdio.h> int main(void) { const int secret_code = 13; int code_entered; do { printf("To enter the triskaidekaphobia therapy club,\n"); printf("please enter the secret code number: "); scanf("%d", &code_entered); ... |
Read now
Unlock full access