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 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.
Study guide
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.
i starts at 1. It stands for the row number.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.i * j followed by a space, staying on the same line.Each row is one pass of the inner loop body. Watch j reset to 1 every time i changes.
| Pass | i | j | Printed i * j | j after j + 1 | j <= 3? | Next step |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 2 | Yes | Back to Print i * j |
| 2 | 1 | 2 | 2 | 3 | Yes | Back to Print i * j |
| 3 | 1 | 3 | 3 | 4 | No | Print new line, i becomes 2, j restarts at 1 |
| 4 | 2 | 1 | 2 | 2 | Yes | Back to Print i * j |
| 5 | 2 | 2 | 4 | 3 | Yes | Back to Print i * j |
| 6 | 2 | 3 | 6 | 4 | No | Print new line, i becomes 3, j restarts at 1 |
| 7 | 3 | 1 | 3 | 2 | Yes | Back to Print i * j |
| 8 | 3 | 2 | 6 | 3 | Yes | Back to Print i * j |
| 9 | 3 | 3 | 9 | 4 | No | Print 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.
FOR i = 1 TO 3
FOR j = 1 TO 3
PRINT i * j (same line)
NEXT j
PRINT new line
NEXT i
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
#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;
}
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();
}
}
}
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.
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.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.
Change the inner test from j <= 3? to j <= i? and the print step to Print "*".
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.
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.
| Symbol | Shape to draw on paper | Where it appears here | Why |
|---|---|---|---|
| Terminator | Rounded box | Start and End | One way in, one way out. |
| Process | Rectangle | Set i = 1, Set j = 1, Set j = j + 1, Set i = i + 1 | Each one changes a counter and has one exit. |
| Decision | Diamond | i <= 3? and j <= 3? | Each loop has its own test with Yes and No exits. |
| Input/output | Parallelogram | Print i * j and Print new line | They send output to the screen. |
| Loop | A decision whose flow line returns to an earlier step | The 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 line | Arrow | Every arrow | Arrows 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.
Each link opens the editor with a prompt already filled in. Change the wording, then generate your own 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.
Type any system, process, or schema in plain English. ChartCraft will draw it in seconds.