C - Do-While Loop

The do-while loop executes the body at least once, then repeats while the condition is true.

Learning Objectives

  • Use do-while for input-validation and menu loops.

Prerequisites

Example

#include <stdio.h>

int main(void) {
    int i = 0;
    do {
        printf("%d\n", i++);
    } while (i < 3);
}

Checks for Understanding

  1. How many times does the loop body run if the condition is initially false?
Show answers
  1. Once.