πŸ“Š Flowcharts β€” Loops Β· goto Β· break Β· continue
0%
C Programming  Β·  Flowcharts  Β·  Control Flow

Flowcharts in C β€”
Loops, goto, break & continue

Every loop and control jump visualised as a proper flowchart β€” symbols, connectors, decision diamonds, and loop-back arrows. Seven complete examples from for-loop basics to goto, break, and continue with annotated diagrams and working C code side by side.

Start/End
Oval / Terminal
Process
Rectangle / Process
Yes/No?
Diamond / Decision
I/O
Parallelogram / I/O
Arrow / Flow line
A
Circle / Connector
FC1
πŸ” for Loop β€” Init, Condition, Body, Update
Print 1 to 5 β€” four flowchart zones: initialise β†’ test β†’ body β†’ update β†’ loop back
for loop
A for loop has four parts that map directly to flowchart zones: Init (rectangle β€” runs once), Condition (diamond β€” tested before every iteration), Body (rectangle β€” runs if condition is true), Update (rectangle β€” runs after body, then loops back to condition). The back arrow from Update to Condition is the visual signature of a loop β€” it shows the repeated cycle. When the condition becomes false, the No arrow exits the loop.
Flowchart for(i=1; i<=5; i++)
START Init: i = 1 β‘  i <= 5? β‘‘ YES NO print(i) β‘’ Update: i++ β‘£ loop back END
for_loop.c
C
#include <stdio.h>
int main() {
    /* β‘  Init */
    for (int i = 1;
         i <= 5;   /* β‘‘ Condition */
         i++) {      /* β‘£ Update   */
        printf("%d\n", i); /* β‘’ Body */
    }
    return 0;
}
output
1
2
3
4
5
Four zones map exactly to the four parts of a for statement. The flowchart loop-back arrow from Update β†’ Condition is the visual proof that something repeats.
fc2 β€” while loop
FC2
πŸ”„ while Loop β€” Condition at the Top, Body Below
Sum of digits of a number β€” condition tested BEFORE body β€” may never run
while loop
A while loop tests its condition before entering the body β€” if the condition is false on the very first check, the body never executes. The flowchart shows this: the decision diamond comes immediately after the start/init, before any process box. The loop-back arrow goes from the bottom of the body directly back up to the diamond β€” skipping the init (which stays outside the loop). Example: extract digits of a number by repeatedly dividing by 10 until the number becomes 0.
Flowchart while(n > 0)
START n = 5765; sum = 0 n > 0? YES NO sum += n % 10 n = n / 10 print(sum) END
while_sum_digits.c
C
#include <stdio.h>
int main() {
    int n = 5765, sum = 0;

    while (n > 0) {       /* condition first */
        sum += n % 10;    /* last digit      */
        n   /= 10;        /* remove digit    */
    }

    printf("Digit sum = %d\n", sum);
    return 0;
}
output
Digit sum = 23
Key difference from do-while: if n = 0 at the start, the body never runs and sum stays 0. The condition diamond blocks entry to the body the moment it's false β€” even on the first check.
fc3 β€” do-while loop
FC3
πŸ” do-while Loop β€” Body First, Condition at the Bottom
Menu input validator β€” body ALWAYS runs at least once β€” condition tested AFTER
do-while
The do-while loop puts the condition diamond below the body. The body always executes at least once β€” guaranteed. The flowchart shows: Start β†’ Body β†’ Condition Diamond. If the condition is true, the arrow loops back up to the body (opposite direction from while). If false, it exits. Perfect for menu-driven programs where you must show the menu at least once before checking the choice.
Flowchart do { } while(choice < 1)
START print menu read choice validate choice choice < 1? YES β€” repeat NO β€” exit run menu option END
do_while_menu.c
C
#include <stdio.h>
int main() {
    int choice;

    do {                         /* body runs first */
        printf("1.Add 2.Del 3.Exit\n");
        printf("Enter choice: ");
        scanf("%d", &choice);
    } while (choice < 1      /* condition after */
          || choice > 3);

    printf("Valid choice: %d\n", choice);
    return 0;
}
output (invalid then valid)
1.Add 2.Del 3.Exit
Enter choice: 0
1.Add 2.Del 3.Exit
Enter choice: 2
Valid choice: 2
do-while vs while: In the flowchart, the loop-back arrow in do-while points upward to the body. In while, the loop-back arrow points upward to the condition diamond. This single difference is the entire distinction between the two loops.
fc4 β€” break
FC4
β›” break β€” Escape the Loop Immediately
Linear search β€” break exits the loop the moment the target is found
break
break adds a second exit path to the loop β€” the early exit. In the flowchart, there are now two arrows leaving the body: the normal loop-back arrow, and a new break arrow that jumps out of the loop entirely, bypassing the condition check. A second decision diamond inside the body represents the if that triggers the break. The moment it fires, execution jumps past the loop to the next statement.
Flowchart break on found
START i=0; target=30 i < n? YES NO arr[i]==target? YES BREAK NO i++ print found/not found END
break_search.c
C
#include <stdio.h>
int main() {
    int arr[] = {10,20,30,40,50};
    int n=5, target=30, found=-1;

    for(int i=0; i<n; i++) {
        if(arr[i] == target) {
            found = i;
            break;  /* EXIT loop NOW */
        }
    }

    if(found >= 0)
        printf("Found at index %d\n",found);
    else
        printf("Not found\n");
    return 0;
}
output
Found at index 2
break only exits ONE loop. In nested loops, break only exits the innermost loop it is inside. The outer loop continues. Use a flag variable or goto if you need to exit multiple loops at once.
fc5 β€” continue
FC5
⏭️ continue β€” Skip This Iteration, Loop Again
Print odd numbers only β€” continue skips even numbers, jumps back to update
continue
continue does not exit the loop β€” it skips the rest of the current iteration and jumps directly to the update step (for a for loop) or back to the condition (for a while loop). In the flowchart, the continue arrow bypasses the remaining process boxes in the body and connects directly to the update/condition β€” it is a short-circuit back to the top, not an exit. The loop keeps running; you just skipped this one iteration.
Flowchart continue skips even
START i = 1 i <= 10? YES NO i%2 == 0? YES CONTINUE NO print(i) i++ END
continue_odd.c
C
#include <stdio.h>
int main() {
    printf("Odd numbers 1-10:\n");

    for(int i=1; i<=10; i++) {
        if(i % 2 == 0)
            continue; /* skip even β€” jump to i++ */

        printf("%d\n", i); /* only reached for odd i */
    }
    return 0;
}
output
Odd numbers 1-10:
1
3
5
7
9
continue in for vs while: In a for loop, continue jumps to the update expression (i++) first, then to the condition. In a while loop, continue jumps directly to the condition. If you put the update inside a while body after a continue, it gets skipped β€” this causes an infinite loop.
fc6 β€” nested loops with break + continue
FC6
πŸ”— Nested Loops β€” Connector Symbols + break in Inner Loop
Multiplication table β€” inner loop uses connector circles to keep flowchart readable
Nested + Connector
When loops are nested, flowcharts become complex. Connector circles (labeled A, B, C…) allow the chart to jump between sections without crossing arrows everywhere β€” you draw circle A at the exit and circle A again at the entry point, and the reader knows they connect. The inner loop for a multiplication table also demonstrates break inside a nested loop β€” the break only exits the inner loop, and the outer loop continues.
Flowchart β€” nested for loops with connector symbols
START Outer Init: i = 1 i <= 3? YES A NO END B Outer: i++ A Inner: j = 1 j <= 5? YES print iΓ—j j++ NO B OUTER LOOP INNER LOOP
nested_loops.c
C
#include <stdio.h>
int main() {
    for(int i=1; i<=3; i++) {    /* outer loop β€” connector A enters inner */
        for(int j=1; j<=5; j++) { /* inner loop */
            printf("%dΓ—%d=%-3d  ", i, j, i*j);
        }                              /* connector B returns to outer */
        printf("\n");
    }
    return 0;
}
output
1Γ—1=1   1Γ—2=2   1Γ—3=3   1Γ—4=4   1Γ—5=5
2Γ—1=2   2Γ—2=4   2Γ—3=6   2Γ—4=8   2Γ—5=10
3Γ—1=3   3Γ—2=6   3Γ—3=9   3Γ—4=12  3Γ—5=15
Connector circles (A, B) are the flowchart equivalent of goto labels β€” they name a point in the flow so you can connect it from elsewhere without drawing a long crossing arrow. Use them whenever an arrow would cross another or the flowchart becomes too wide.
fc7 β€” goto
FC7
🏷️ goto β€” Jump to a Label Anywhere in the Function
Exit nested loops instantly β€” goto jumps directly to a labelled point β€” use with care
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 connector or process box. The most legitimate use of goto in C is breaking out of multiple nested loops β€” where a single break only exits the innermost loop. With goto, you jump directly to code after all the loops.
Flowchart β€” goto exits nested loops in one jump
START i < rows? NO→END YES j < cols? YES process grid[i][j] error found? YES → goto error_exit NO j++; i++ error_exit: handle error END END
goto_nested_exit.c
C
#include <stdio.h>
int main() {
    int grid[3][3] = {{1,2,3},{4,-1,6},{7,8,9}};

    for(int i=0; i<3; i++) {
        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 over BOTH loops */
        }
    }
    printf("All values OK.\n");
    return 0;

error_exit:                          /* label β€” goto lands here */
    printf("Error: negative value found!\n");
    return 1;
}
output
Check [0][0]=1
Check [0][1]=2
Check [0][2]=3
Check [1][0]=4
Check [1][1]=-1
Error: negative value found!
Use goto sparingly. The only widely accepted use of goto in C is exiting nested loops or centralised error/cleanup handling (common in Linux kernel code). Never use it to jump into a loop, over initialisations, or create spaghetti flow. In modern C, prefer a flag variable or restructuring functions over goto in most cases.
Keyword What it does Flowchart arrow direction Resumes at
breakExits the current loop or switch immediatelyArrow exits loop box downwardFirst statement after the loop
continueSkips rest of body, starts next iterationArrow skips to update/conditionUpdate step (for) or condition (while)
goto labelJumps unconditionally to labelled statementLong arrow crosses loop boundariesThe named label anywhere in function
checklist
  • Flowchart symbols: Oval = Start/End. Rectangle = Process. Diamond = Decision (Yes/No). Parallelogram = Input/Output. Circle = Connector. Arrow = flow direction.
  • FC1 β€” for loop: Four zones β€” Init (once), Condition (diamond before body), Body, Update. Loop-back arrow from Update β†’ Condition. NO arrow exits loop.
  • FC2 β€” while loop: Condition diamond comes BEFORE body. If false on first check, body never runs. Loop-back arrow goes from body bottom directly up to condition diamond.
  • FC3 β€” do-while: Body comes BEFORE condition diamond. Body always runs at least once. YES arrow from condition loops BACK UP to body. NO arrow exits.
  • FC4 β€” break: Second inner decision diamond inside body. YES β†’ break arrow exits loop entirely downward. Resumes at first statement AFTER the loop. Only exits ONE level.
  • FC5 β€” continue: Inner decision. YES β†’ continue arrow bypasses rest of body and goes directly to Update (for) or Condition (while). Loop does NOT exit β€” next iteration starts.
  • FC6 β€” nested + connector: Connector circles (A, B) label entry/exit points so arrows don't cross. A connects outer-YES to inner loop entry. B connects inner-NO back to outer update.
  • FC7 β€” goto: Long arrow crosses loop boundaries and lands at labelled statement. Only accepted use: exit nested loops or centralised error handling. Never jump INTO loops.