September 1998
Intermediate to advanced
848 pages
20h 13m
English
Some of the while loop examples have been indefinite loops. That means you don't know in advance how many times the loop will be executed before the expression becomes false. For instance, when Listing 6.1 used an interactive loop to sum integers, you didn't know beforehand how many integers would be entered. Other examples, however, have been counting loops. They execute a predetermined number of repetitions. Listing 6.8 is a short example of a while counting loop.
/* sweetie1.c -- a counting loop */ #include <stdio.h> #define NUMBER 22 int main(void) { int count = 1; /* initialization */ while (count <= NUMBER) /* test */ { printf("Be my Valentine!\n"); /* action */ ... |
Read now
Unlock full access