Summary: The do while Statement

Keywords

The keywords for the do while statement are do and while.

General Comments

The do while statement creates a loop that repeats until the test expression becomes false or zero. The do while statement is an exit-condition loop; the decision to go through one more pass of the loop is made after the loop has been traversed. Therefore, the loop must be executed at least once. The statement part of the form can be a simple statement or a compound statement.

Form

do
    statement
while (expression);

The statement portion is repeated until the expression becomes false or zero.

Example

do
    scanf("%d", &number)
while(number != 20);

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.