Flowchart Updated 12/2/2026

Do-While Loop Flowchart

Do-while loop flowchart: the loop body runs first, then a decision at the bottom tests the condition and sends the flow back up while it is true. With a trace table for n = 3, pseudocode, and tested Python, C and Java code.

do-while loopflowchartloopscontrol flowiterationprogramming
7 nodes 7 connections

Study guide

Do-While Loop FlowchartStartRead nPrint nSet n = n - 1n > 0?Print "Done"EndYesNo
Do-While Loop Flowchart. Source: https://www.chartcraft.dev/examples/do-while-loop-flowchart

What the do-while loop flowchart shows

A do-while loop runs its body first and tests its condition afterwards, so the body always runs at least once. In a flowchart that means the decision diamond sits below the loop body, and its Yes arrow goes back up to the first step of the body.

The example on this page counts down from n: it prints n, subtracts 1, and repeats while n > 0.

Do-while loop flowchart, step by step

  1. terminator StartEvery flowchart begins with one Start terminator.
  2. input/output Read nThe program reads a whole number and stores it in n. Reading a value is input, so on paper this step is a parallelogram.
  3. input/output Print nThis is the first step of the loop body. It prints the current value of n. Notice that nothing has been tested yet: the flow reaches the body without passing a decision.
  4. process Set n = n - 1The second step of the body makes n one smaller. This is the update step. Without it the condition would never change and the loop would never stop.
  5. decision n > 0?Only now is the condition tested. Yes sends the flow back up to Print n for another pass. No leaves the loop. A do-while loop tests its condition once per pass, at the end of the pass.
  6. input/output Print "Done"The first step after the loop. It runs once, when the condition has become false.
  7. terminator EndOne End terminator closes the flowchart.

Dry run: trace table for n = 3

Follow the flowchart with n = 3. Each row is one pass through the loop body, ending at the decision.

Passn at start of passPrintedn after n = n - 1n > 0?Next step
1332YesBack to Print n
2221YesBack to Print n
3110NoPrint "Done", then End

Three passes, three tests. The output is 3, 2, 1 and then Done.

Do-while loop pseudocode

Pseudocode
READ n
DO
    PRINT n
    n = n - 1
WHILE n > 0
PRINT "Done"

Do-while loop in Python, C and Java

Python
n = int(input())

# Python has no do-while statement.
# Loop forever, then leave when the condition is false.
while True:
    print(n)
    n = n - 1
    if not (n > 0):
        break

print("Done")
C
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    do {
        printf("%d\n", n);
        n = n - 1;
    } while (n > 0);   /* the semicolon is required */

    printf("Done\n");
    return 0;
}
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        do {
            System.out.println(n);
            n = n - 1;
        } while (n > 0);   // the semicolon is required

        System.out.println("Done");
    }
}
Input typed at the keyboard
3
Output of all three programs
3
2
1
Done

All three programs were compiled and run with the input 3 before this page was published. The output shown is exactly what they printed, and it matches the trace table. Python has no do-while statement, so the Python version uses while True with a break at the bottom of the body, which follows the same flowchart.

Mistakes examiners see most

  • Drawing the decision above the body. That is a while loop, which can skip its body completely. In a do-while flowchart the first box after the input is the body, and the diamond comes after it.
  • Sending the Yes arrow to the wrong place. The Yes arrow must return to the first step of the body (Print n). If it goes back to Read n, the program asks for a new number on every pass. If it goes back to the diamond itself, nothing ever changes.
  • Forgetting that the body runs once even when the condition is false. With n = 0 this flowchart still prints 0 before it tests n > 0. Many exam answers say that nothing is printed.
  • Leaving out the semicolon in C and Java. The statement ends with while (n > 0);. A while loop has no semicolon there, a do-while loop must have one.

Practice questions with worked answers

Q1 What does the flowchart print when the input is n = 0?

It prints 0 and then Done.

The body runs before any test, so Print n shows 0 and then n becomes -1. The decision asks whether -1 is greater than 0. The answer is No, so the loop ends after one pass.

A while loop with the same condition would print only Done, because it would test 0 > 0 first.

Q2 For n = 5, how many times is the body executed and how many times is the condition tested?

The body runs 5 times and the condition is tested 5 times.

In a do-while loop each pass ends with exactly one test, so the two counts are always equal. The tests are 4 > 0, 3 > 0, 2 > 0, 1 > 0 (all Yes) and 0 > 0 (No).

A while loop that prints the same five numbers would test its condition 6 times: five times Yes and one final No.

Q3 Rewrite the pseudocode so that it uses a while loop and prints nothing except Done when n is 0 or negative. What changes in the flowchart?
Pseudocode
READ n
WHILE n > 0
    PRINT n
    n = n - 1
ENDWHILE
PRINT "Done"

In the flowchart the diamond n > 0? moves up, between Read n and Print n. Its No arrow goes straight to Print "Done". The arrow that leaves Set n = n - 1 goes back up to the diamond instead of down into it.

Flowchart symbols used and why

SymbolShape to draw on paperWhere it appears hereWhy
TerminatorRounded boxStart and EndA flowchart has one entry point and, here, one exit.
Input/outputParallelogramRead n, Print n and Print "Done"These steps move data in or out of the program. They are the steps marked data in the diagram.
ProcessRectangleSet n = n - 1It changes a stored value and has exactly one way out.
DecisionDiamondn > 0?A yes-or-no question with two labelled exits.
LoopA decision whose flow line returns to an earlier stepThe Yes arrow from n > 0? back up to Print nA flow line that returns to an earlier step is what makes a loop. Because the diamond is below the body, this is a post-test loop.
Flow lineArrowEvery arrowArrows show the order of the steps. Only the loop arrow points upward.

In the interactive diagram every step is a labelled card: the small word above each step names its kind (process, decision or data). When you draw this flowchart by hand, use the standard shapes in the table. The full list is on the flowchart symbols page.

Make your own version

Each link opens the editor with a prompt already filled in. Change the wording, then generate your own flowchart.

How can I use this flowchart?

Download the Do-While Loop Flowchart as a PNG or SVG, or open it in the studio to edit your own copy. To draw a similar flowchart from a description, use the flowchart generator; for notation and a step-by-step walkthrough, read how to make a flowchart; and browse more flowchart examples for related layouts.

Try the studio with your own description.

Type any system, process, or schema in plain English. ChartCraft will draw it in seconds.