O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Indefinite Loops and Counting Loops

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 example, 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.10 is a short example of a while counting loop.

Listing 6.10. The sweetie1.c Program
 // sweetie1.c -- a counting loop #include <stdio.h> int main(void) { const int NUMBER = 22; int count = 1; // initialization while (count <= NUMBER) // test { printf("Be my Valentine!\n"); // action count++; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required