Previous Next

do...while Loop

The do-while loop is the same as the while loop. This loop would run its statements at least once, even if the condition is not met for the first time.

Syntax

do {
  // block of code
} while (condition);

Example:

#include <stdio.h>

int main()
{
    int i = 0;

    do
    {
        printf("%d", i);
        i++;
    } while (i < 4);

    return 0;
}

Output:

0 1 2 3
Previous Next