VM-LEARNING /class.xi ·track.cs ·ch-2-7 session: 2026_27
$cd ..

~/Flow of Control — Introduction

root@vm-learning ~ $ open ch-2-7
UNIT 2 ▪ CHAPTER 7
13
Flow of Control — Introduction
Sequential · Conditional · Iterative · The role of indentation
Flow of control (or control flow) is the order in which statements are executed in a program. A plain program runs its statements one after another, top to bottom — but real programs often need to skip some lines or repeat others. The three fundamental patterns of flow — sequential, conditional, and iterative — together give you everything required to express any algorithm. Python marks the groupings of statements not with braces { } but with indentation, which makes this chapter an important introduction to how Python sees your code.
The theorem. A classic 1966 result by Böhm and Jacopini proved that every computable algorithm can be expressed using only these three flow patterns. goto is not required. Modern structured programming — Python included — is built on this idea.
Learning Outcome 1: Explain what flow of control means and the role of indentation in Python.

13.1 The Three Patterns of Flow

The three fundamental control-flow patterns: 1. Sequential one after another Statement 1 Statement 2 Statement 3 Statement 4 execution follows the order 2. Conditional go down one branch Statement 1 cond ? Yes A No B Statement 3 only A or B runs, not both 3. Iterative (Loop) repeat while condition is True Statement 1 cond ? True loop body False body repeats each time condition is True

13.2 Indentation — How Python Groups Statements

Most programming languages use braces { } to mark the start and end of a block of statements. Python does not. Instead, Python uses indentation — the horizontal white-space at the start of each line. Every indented "step" is a sub-block of the line above.

13.2.1 The rules

Indentation in action — each colour shows a block:
if marks >= 33:                 # block starts
    print("Pass")                  # ← 4 spaces in
    if marks >= 75:             # nested block
        print("Distinction")       # ← 8 spaces in
    print("Well done")             # back to 4 spaces — still inside outer if
print("Result card printed")       # ← 0 spaces — outside the if
Why not braces? Python's designer chose indentation to force the visual structure of the code to match the logical structure. In other languages you can have well-indented-but-wrong or badly-indented-but-right code; in Python the two always agree.

13.2.2 Common indentation mistakes

MistakeProblem
Missing indent after ifIndentationError: expected an indented block
Extra indent on a normal statementIndentationError: unexpected indent
Inconsistent depth inside the same block (e.g., first line 4 spaces, next line 5)IndentationError: unindent does not match any outer indentation level
Mixing tabs and spacesLooks the same to the eye, but Python considers them different. Use your editor's "convert to spaces" option.
Always use 4 spaces per indent level (PEP 8 style). Configure your editor to insert 4 spaces when you press the Tab key — this prevents the tabs-vs-spaces trap.
Learning Outcome 2: Describe sequential, conditional and iterative flow and recognise each in Python code.

13.3 Sequential Flow

The sequential (or default) flow is the simplest: statements execute in the order they are written, top to bottom, one after the other. No decisions, no repetition — just straight-line execution.

Sequential example — compute a circle's area:
radius = float(input("Radius: "))     # line 1 runs first
pi     = 3.14159                       # then line 2
area   = pi * radius ** 2                # then line 3
print("Area =", area)                   # finally line 4
The program does exactly four things in the exact order shown.
Until you introduce if or while, every Python program is purely sequential. All the programs from Chapter 8 through Chapter 11 followed this pattern.

13.4 Conditional Flow

A conditional (or decision) flow runs a different piece of code depending on whether a condition is True or False. It lets a program make choices. The Python keywords are if, elif (else-if) and else.

Conditional example — pass / fail:
marks = int(input("Enter marks: "))

if marks >= 33:                     # is the condition True?
    print("Pass")                    # Yes-branch
else:
    print("Fail")                    # No-branch
Only one of the two print() calls runs — never both.

The full set of conditional forms (if, if-else, if-elif-else), flowcharts, nested-if and worked programs are covered in Chapter 14 — Conditional Statements.

13.5 Iterative Flow

An iterative (or loop) flow runs the same block of code several times. Python provides two loop keywords:

Iterative example — print 1 to 5:
# for-loop form
for i in range(1, 6):
    print(i)                        # 1, 2, 3, 4, 5

# equivalent while-loop
n = 1
while n <= 5:
    print(n)
    n += 1

The full set of loop forms plus range() (start / stop / step), forwhile conversion, break, continue and nested loops are covered in Chapter 15 — Iterative Statements.

13.6 Putting It Together

Real programs use all three patterns. A small example combining sequence, decision and repetition:

Sum of only the even numbers from 1 to 10:
total = 0                               # sequential — initialise
for n in range(1, 11):                  # iterative — visit 1 to 10
    if n % 2 == 0:                     # conditional — only even numbers
        total += n
print("Sum of evens =", total)           # sequential — show result
Output: Sum of evens = 30 (2 + 4 + 6 + 8 + 10)

13.7 Comparison at a Glance

FlowKeyword(s)Runs the block…Typical use
Sequential(none — the default)once, top to bottomthe default; calculations, printing
Conditionalif, elif, elsezero or one time, based on a conditionbranching — pass/fail, discount/no-discount, grade
Iterativefor, whilezero or more times, as long as a condition holdsrepetition — sums, tables, counting, processing each student

📌 Quick Revision — Chapter 13 at a Glance

  • Flow of control = order in which statements are executed.
  • Three fundamental patterns (Böhm–Jacopini theorem, 1966): Sequential · Conditional · Iterative. These three together can express every algorithm.
  • Sequential flow — statements execute top-to-bottom, one after another. The default of every Python program.
  • Conditional flowif, elif, else. Run a block only when a condition is True; choose between two (or more) paths.
  • Iterative flowfor or while. Repeat a block as long as a condition holds or for every item of a sequence.
  • Python uses indentation (not { }) to mark blocks. Every indented step is a sub-block of the line above.
  • Indent rules:
    • A line ending with : opens a block.
    • All statements inside must share the same depth (use 4 spaces by PEP 8).
    • Return to the previous depth to end the block.
    • Never mix tabs and spaces.
  • Mis-indentation → IndentationError. A missing indent gives "expected an indented block"; an extra indent gives "unexpected indent".
  • Real programs combine all three flows — e.g., "loop through marks, add up only the passing ones, print the total".
  • Details of conditional statements → Chapter 14 · details of loops → Chapter 15.
🧠Practice Quiz — test yourself on this chapter