Skip to content

do / while

C++ post-condition loop

Flowchart (ISO 5807)

NoYesStartInput nc = 0c = c + 1n = n / 10n ≤ 0Return cEndFigure 1 — countDigits

Source code

C++
int countDigits(int n) {
    int c = 0;
    do {
        c++;
        n /= 10;
    } while (n > 0);
    return c;
}

The editor opens with this code — change it and the chart redraws.

Language
C++
Constructs
post-condition loop
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples