O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

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

The While Loop

Conditionals are one broad type of control structure and loops are the other. The C language supports two loop formats: while (and its sibling do…while) and for. Each loop type accomplishes the same thing—repeatedly performing some statements for a certain duration—but in slightly different ways.

The while loop is like an if conditional in that it checks a condition and then executes some statements if it's true:

while (condition) {
   /* Do whatever. */
}

Once the loop has successfully executed its statements, it will then recheck the condition. If the condition is still true, the process will be repeated. If the condition is false, the execution of the loop is over and the program will continue running (Figure 4.13).

Figure 4.13. ...

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