Flowcharts — Loops · break · continue · goto · Connectors
0%
C Programming  ·  Flowcharts

Flowcharts in C —
Loops, break, continue & goto

Every loop and jump statement visualised as a proper flowchart — symbols explained, connector circles demonstrated, and the complete goto nested-loop flowchart built step by step.

FC1
Symbols & Connectors
FC2-4
for · while · do-while
FC5-6
break · continue
FC7
goto — nested exit
FC0
📐 Flowchart Symbols & Connectors — Full Guide
Every standard shape, what it means, and how connector circles keep diagrams clean
Symbols
START/END
Oval / Terminator
Marks the beginning or end of the flowchart
Process
Rectangle
Any computation, assignment, or action
Yes / No
Diamond
Decision — exactly two exits: YES and NO
Input/Output
Parallelogram
Read input from user or display output
A
Circle — Connector
Links two parts of a flowchart without crossing arrows
Arrow / Flow line
Shows direction of execution

🔵 What are Connector Circles?

When a flowchart grows large or the arrows would have to cross each other (making it unreadable), we use connector circles. A connector is a small circle containing a letter or number (A, B, 1, 2…). It works as a labelled bridge:

Outgoing connector: instead of drawing a long arrow all the way to the destination, you draw an arrow into a circle labelled A. This means "flow continues at the matching A circle".

Incoming connector: elsewhere in the diagram (even on another page), an identical circle A with an arrow leaving it shows where the flow resumes. Every label must appear exactly twice — once as the source, once as the destination.

Connectors are used most in nested loops — where the inner loop's exit must reconnect to the outer loop's update step without drawing a long crossing line.

How connector circles work — without vs with connector
❌ Without Connector (arrows cross!) START cond A? YES Work A NO Work B ← arrows cross here! ❌ END ✅ With Connector (clean!) START cond A? YES Work A M NO Work B M ↓ both M connectors lead here END
Connector rule: every label appears exactly twice. Once as the output (arrow going INTO the circle) and once as the input (arrow leaving the circle). If you see three circles labelled "A", the flowchart is wrong. The circle is a portal — one entry, one exit, same label on both ends.
fc2 — for loop
FC2
🔁 for Loop Flowchart — Init · Condition · Body · Update
Four distinct zones — condition diamond before body, loop-back arrow from Update back to Condition
for loop
A for loop has four zones: Init (runs once), Condition (diamond — if NO, exit), Body (runs each pass), and Update (i++). After Update, the arrow loops back up to the Condition. When Condition is NO, the arrow exits the loop downward.
for(i=0; i<5; i++) — flowchart
START Init: i = 0 i < 5? YES printf(i) Update: i++ NO After loop END
for_loop.c
C
#include <stdio.h>

int main() {
    /* Init ─ Condition ─ Body ─ Update */
    for (int i = 0; i < 5; i++) {
        printf("i = %d\n", i);
    }
    printf("After loop\n");
    return 0;
}
output
i = 0
i = 1
i = 2
i = 3
i = 4
After loop
for loop — zone order
Order
Init once
→ Condition
→ Body
→ Update
→ Condition…
Exit
Condition = NO → exits
← arrow goes right, then down to After loop
fc3 — while · fc4 — do-while
FC3-4
🔄 while vs do-while — Condition Placement
while checks before body (can run 0 times); do-while checks after body (always runs at least once)
while · do-while
FC3 — while loop
START cond? YES body NO after loop END
while: Condition is checked BEFORE body — if false from the start, body never runs.
FC4 — do-while loop
START body (runs) always first! cond? YES NO after loop END
do-while: Body runs FIRST, condition checked after — always runs at least once.
fc5 — break · fc6 — continue
FC5-6
🛑⏭️ break and continue — Inside-Loop Jump Arrows
break exits loop entirely; continue skips to update/condition — both shown as inner decision diamonds
break · continue
FC5 — break exits loop
START i < n? work break? YES→break NO i++ NO after loop END
FC6 — continue skips to i++
START i < n? YES work skip? YES→continue NO more work i++ ← continue lands here NO after loop END
break vs continue — where the arrow goes
break YES
exits loop box
→ after loop
← loop is done permanently
continue YES
skips to i++
→ condition check
← loop still running, just skipped this iteration
fc7 — goto — nested loop exit
FC7
🏷️ goto — Complete Flowchart: Nested Loop Exit
The goto arrow crosses both loop boundaries and lands at the error_exit label — with correct START and END
goto
goto causes an unconditional jump to a labelled statement anywhere in the same function. In the flowchart, a goto is represented as an arrow that crosses over normal flow and lands at a labelled box. The most legitimate use in C is breaking out of multiple nested loops — where a single break only exits the innermost loop. The full flowchart below shows: outer loop (rows), inner loop (cols), value check diamond, goto error_exit arrow crossing both loops, then the two separate END paths — one for "all OK" and one for "error found".
🗺️ Complete goto flowchart — goto_nested_exit.c — two END paths
START Init: i = 0 i < 3? YES NO→OK Init: j = 0 j < 3? NO i++ YES print grid[i][j] grid[i][j] < 0? NO j++ YES → goto error_exit "All OK" return 0 END (OK) error_exit: label printf("Error: negative found!") return 1 END (ERROR) LEGEND loop flow NO / exit goto jump OK path
goto_nested_exit.c
C
#include <stdio.h>

int main() {
    int grid[3][3] = {
        { 1,  2,  3},
        { 4, -1,  6},   /* -1 at [1][1] */
        { 7,  8,  9}
    };

    /* Outer loop: rows */
    for (int i = 0; i < 3; i++) {
        /* Inner loop: columns */
        for (int j = 0; j < 3; j++) {
            printf("Check [%d][%d]=%d\n",
                   i, j, grid[i][j]);

            if (grid[i][j] < 0)
                goto error_exit; /* jump BOTH */
        }
    }

    /* Reached only if NO negative found */
    printf("All values OK.\n");
    return 0;

error_exit:              /* label — goto lands here */
    printf("Error: negative value!\n");
    return 1;
}
output — run 1 (has -1)
Check [0][0]=1
Check [0][1]=2
Check [0][2]=3
Check [1][0]=4
Check [1][1]=-1
Error: negative value!
output — run 2 (all positive)
Check [0][0]=1
Check [0][1]=2
...
Check [2][2]=9
All values OK.
execution paths — two distinct END nodes
Path A (error)
-1 found
goto fires
error_exit:
return 1
END(ERROR)
Path B (OK)
all loops done
"All OK"
return 0
END(OK)
Use goto sparingly. The two accepted uses are: (1) exit nested loops as shown here, (2) centralised resource cleanup at the end of a function. Never use goto to jump backward into a loop, jump over variable initialisations, or create spaghetti flow. For everything else — use if, while, for, return, or break.
break · continue · goto — flowchart arrow comparison
break
exits loop box
→ after loop
← short downward arrow past loop boundary
continue
skips body rest
→ i++ update
← arrow bypasses rest of body, lands at update
goto
long purple arrow
crosses all loops
→ label box
← the goto arrow is drawn crossing loop boundaries
checklist
  • Flowchart symbols: Oval = Start/End. Rectangle = Process. Diamond = Decision (Yes/No). Parallelogram = Input/Output. Circle = Connector. Arrow = flow direction. Each diamond has exactly two exits.
  • Connector circles: Used to link two parts of a flowchart without crossing arrows. A labelled circle appears twice — once as the output (arrow into it) and once as the input (arrow leaving it). Every label must appear exactly twice.
  • FC2 — for loop: Init (once) → Condition diamond → YES: Body → Update → back to Condition. NO: exits loop. Update arrow loops back UP to Condition.
  • FC3 — while: Condition diamond comes BEFORE body. If condition false on first check, body never runs. Loop-back arrow from body bottom to condition diamond.
  • FC4 — do-while: Body comes BEFORE condition diamond. Body always runs at least once. YES from condition loops back UP to body. NO exits.
  • FC5 — break: Inner decision diamond inside loop body. YES (break) arrow exits loop entirely — joins the NO-exit path to "after loop". NO continues to update and loops again.
  • FC6 — continue: Inner decision. YES (continue) arrow bypasses rest of body and lands directly on the i++ update box. Loop does NOT exit — next iteration begins.
  • FC7 — goto: A long coloured arrow crosses all loop boundaries and lands at the labelled box (error_exit:). Two separate END nodes — one for the normal path (return 0) and one for the error path (return 1). Only accepted use: exit nested loops or centralised cleanup.