Flowchart Updated 12/2/2026

Nested Loop Flowchart

Nested loop flowchart: an outer loop over rows and an inner loop over columns that prints a 3 by 3 multiplication table. With a trace table of all 9 inner passes, pseudocode, and tested Python, C and Java code.

nested loopflowchartloopsfor loopprogramming
10 nodes 11 connections

Study guide

Nested Loop FlowchartStartSet i = 1i <= 3?Set j = 1j <= 3?Print i * jSet j = j + 1Print new lineSet i = i + 1EndYesNoYesNo
Nested Loop Flowchart. Source: https://www.chartcraft.dev/examples/nested-loop-flowchart

What the nested loop flowchart shows

A nested loop is a loop inside the body of another loop: for every single pass of the outer loop, the inner loop runs all the way through. In a nested loop flowchart you see two decision diamonds, and the inner loop's arrow circles back inside the outer loop's arrow, like a small wheel turning inside a big one.

The example prints a 3 by 3 multiplication table. The outer loop picks the row i, the inner loop walks the columns j.

Nested loop flowchart, step by step

  1. terminator StartOne Start terminator opens the flowchart.
  2. process Set i = 1The outer counter i starts at 1. It stands for the row number.
  3. decision i <= 3?The outer test. Yes means there is still a row to print. No means all three rows are done and the program ends.
  4. process Set j = 1The key step of every nested loop: j is reset to 1 inside the outer loop, at the start of every row. If you put it before the outer loop, only the first row prints.
  5. decision j <= 3?The inner test. Yes prints another column. No finishes the row.
  6. input/output Print i * jPrints the product i * j followed by a space, staying on the same line.
  7. process Set j = j + 1Moves to the next column, then the arrow loops back to the inner test. This small loop runs 3 times per row.
  8. input/output Print new lineWhen the inner loop ends, the row is complete, so the program moves to a new line.
  9. process Set i = i + 1Moves to the next row, then the arrow loops back up to the outer test.
  10. terminator EndReached only from the No exit of the outer test.

Dry run: trace table for a 3 by 3 table (i and j from 1 to 3)

Each row is one pass of the inner loop body. Watch j reset to 1 every time i changes.

PassijPrinted i * jj after j + 1j <= 3?Next step
11112YesBack to Print i * j
21223YesBack to Print i * j
31334NoPrint new line, i becomes 2, j restarts at 1
42122YesBack to Print i * j
52243YesBack to Print i * j
62364NoPrint new line, i becomes 3, j restarts at 1
73132YesBack to Print i * j
83263YesBack to Print i * j
93394NoPrint new line, i becomes 4, End

3 outer passes times 3 inner passes gives 9 runs of the inner body. That multiplication is the quickest way to count how often a nested loop body runs.

Nested loop pseudocode

Pseudocode
FOR i = 1 TO 3
    FOR j = 1 TO 3
        PRINT i * j (same line)
    NEXT j
    PRINT new line
NEXT i

Nested loop in Python, C and Java

Python
for i in range(1, 4):          # outer loop: rows
    for j in range(1, 4):      # inner loop: columns
        print(i * j, end=" ")
    print()                    # new line after each row
C
#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 3; i++) {        /* outer loop: rows */
        for (int j = 1; j <= 3; j++) {    /* inner loop: columns */
            printf("%d ", i * j);
        }
        printf("\n");
    }
    return 0;
}
Java
public class Main {
    public static void main(String[] args) {
        for (int i = 1; i <= 3; i++) {        // outer loop: rows
            for (int j = 1; j <= 3; j++) {    // inner loop: columns
                System.out.print(i * j + " ");
            }
            System.out.println();
        }
    }
}
Output of all three programs
1 2 3
2 4 6
3 6 9

All three programs were compiled and run before publishing. Each line ends with one trailing space after the last number, which is invisible on screen. The for statement packs Set j = 1, the test j <= 3 and Set j = j + 1 into one line.

Mistakes examiners see most

  • Setting j = 1 before the outer loop. Then j is already 4 when the second row starts, the inner test fails at once and only one row prints. The reset belongs inside the outer loop.
  • Sending the inner loop's No arrow to End. When the inner loop finishes, only the row is done. The No arrow goes to Print new line and then back to the outer test.
  • Forgetting to update i. Without Set i = i + 1 the outer test is always Yes and the same row prints forever. Every loop, inner or outer, needs its own update step.
  • Adding the passes instead of multiplying them. An outer loop of 3 and an inner loop of 3 run the body 9 times, not 6. Examiners love this question.

Practice questions with worked answers

Q1 How many times does Print i * j run if the outer loop goes to 4 and the inner loop goes to 5?

20 times.

For each of the 4 outer passes, the inner loop runs 5 times, so 4 * 5 = 20. Print new line runs 4 times, once per outer pass.

Q2 Change the flowchart so it prints a triangle of stars: 1 star on row 1, 2 on row 2, 3 on row 3.

Change the inner test from j <= 3? to j <= i? and the print step to Print "*".

Pseudocode
FOR i = 1 TO 3
    FOR j = 1 TO i
        PRINT "*" (same line)
    NEXT j
    PRINT new line
NEXT i

Now the inner loop length depends on the outer counter, which is how most pattern programs work.

Q3 A student moves Print new line so that it sits right after Print i * j, inside the inner loop. What is printed?

Every product appears on its own line: 1, 2, 3, 2, 4, 6, 3, 6, 9, one per line.

The new line now runs 9 times instead of 3, so the table shape disappears. The new line step must sit on the inner loop's No path, outside the inner loop.

Flowchart symbols used and why

SymbolShape to draw on paperWhere it appears hereWhy
TerminatorRounded boxStart and EndOne way in, one way out.
ProcessRectangleSet i = 1, Set j = 1, Set j = j + 1, Set i = i + 1Each one changes a counter and has one exit.
DecisionDiamondi <= 3? and j <= 3?Each loop has its own test with Yes and No exits.
Input/outputParallelogramPrint i * j and Print new lineThey send output to the screen.
LoopA decision whose flow line returns to an earlier stepThe arrow from Set j = j + 1 back to j <= 3?, and from Set i = i + 1 back to i <= 3?Two return arrows, one inside the other, are the picture of a nested loop.
Flow lineArrowEvery arrowArrows show the order of the steps.

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 Nested 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.