Chapter 13 — Flow of Control (Introduction)

Easy-language Notes · Part 1 of 2 (three patterns · indentation · sequential)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Front)

1. The Three Patterns of Flow

The flow of control is the order in which Python runs your statements. By default lines run top-to-bottom; with the right keywords we can choose which lines to run, or repeat them.

A program is like a recipe. By default you follow steps in order. Sometimes the recipe says "if dough is dry, add water" — that is choosing. Sometimes "knead for 5 minutes" — that is repeating.
PatternBehaviourKeywords
SequentialLines run once, top to bottom(default, no keyword)
ConditionalChoose which block runsif, elif, else
IterativeRepeat a block several timesfor, while

Every program is built from these three patterns combined — an idea sometimes called structured programming. A 1966 result by Bohm and Jacopini proved any algorithm can be written using just these three.

Why this matters

  • Knowing the type tells you which keyword to reach for.
  • Each pattern has a different shape on a flowchart — useful in design questions.
  • Mixing them correctly is what makes programs do something useful rather than just print fixed text.
In an exam, look at the first keyword of the line: if → conditional; for / while → iterative; anything else → sequential.

2. Indentation Groups Statements

Most languages use { } to mark a block. Python uses indentation — the leading spaces — to show which lines belong inside an if, a loop, or a function.

Rules

  • Use a consistent count for every level. Standard = 4 spaces.
  • Lines with the same indent are in the same block.
  • The line opening a block ends with a colon.
  • Never mix tabs and spaces in the same file.
  • Going back to a smaller indent ends the inner block.
if marks >= 33:
    print("Pass")        # inside if
    print("Well done")   # still inside
print("End")              # OUTSIDE, always
The first two indented lines run only when the condition is True. The fourth line is back at the outer level, so it always runs.

Common Indentation Mistakes

MistakeResult
No indent after a colon lineIndentationError
Mixed 2-space and 4-space linesIndentationError
Tabs and spaces mixedTabError
Forgotten colon at end of ifSyntaxError
Random extra indent at outer levelIndentationError
Indentation is not just style in Python — it changes meaning. Two lines that look the same but have different indents belong to different blocks. Configure your editor to "show whitespace" so invisible mismatches don't bite you.

3. Sequential Flow

The default behaviour: every statement runs once, from top to bottom. No loops, no decisions.

Sequential flow is like reading a story page by page — you don't skip ahead and you don't read the same page twice. Each instruction runs exactly once.

The IPO Shape

Most short programs follow Input → Process → Output:

  1. Input — read values from the user.
  2. Process — calculate or transform.
  3. Output — show the result.

A pure-sequential program just walks through these steps once and stops.

Area of a rectangle:
l = int(input("L: "))
b = int(input("B: "))
area = l * b
print("Area =", area)
Four lines, four steps — in order. Pure sequential flow.
Simple interest:
p, r, t = 5000, 8.5, 3
si = (p * r * t) / 100
print("SI =", si)
Celsius to Fahrenheit:
c = float(input("C: "))
f = c * 9/5 + 32
print(c, "C =", f, "F")
Three lines — input, process, output.

When sequential is enough

  • The task is a fixed formula with known inputs.
  • No decision is needed.
  • Nothing has to be repeated.
Even programs with if or loops are mostly sequential between those blocks. Sequential is the default; the others are special cases that depart from it.

4. Conditional Flow (Selection)

A conditional statement lets the program pick one of several blocks based on a True/False test. Python uses three keywords: if, elif, else.

FormUse when…
ifOne block, run only when condition holds
if-elseExactly two paths, choose one
if-elif-elseThree or more paths, only one runs
Pass / Fail (two-path):
marks = 47
if marks >= 33:
    print("Pass")
else:
    print("Fail")
Grade ladder (multi-path):
m = 67
if m >= 90: g = "A"
elif m >= 75: g = "B"
elif m >= 60: g = "C"
else: g = "D"
print(g)        # C
Python tests top-to-bottom; the first True branch runs, the rest are skipped.

If-elif vs separate ifs

Three separate if statements run their blocks independently — multiple can be True. An if-elif-else ladder runs at most one block. Pick based on whether the conditions are mutually exclusive.

Each if/elif/else line ends with a colon. Only one branch runs per execution. Order matters — put the most specific condition first.

Chapter 13 — Flow of Control (Introduction)

Easy-language Notes · Part 2 of 2 (conditional · iterative · comparison)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Back)

5. Iterative Flow (Loops)

An iterative statement repeats a block several times. Python provides for and while.

for — counted repetition

Use when you know how many times to run, or want to walk through every item of a sequence.

for i in range(1, 6):
    print(i, i*i)
Prints 1 1, 2 4, 3 9, 4 16, 5 25.

range(start, stop, step) generates numbers from start up to but not including stop:

  • range(5) → 0, 1, 2, 3, 4
  • range(1, 6) → 1, 2, 3, 4, 5
  • range(0, 10, 2) → 0, 2, 4, 6, 8
  • range(10, 0, -1) → 10 down to 1

while — condition-controlled repetition

Use when you don't know the count in advance.

n = 5
while n > 0:
    print(n)
    n -= 1
Prints 5, 4, 3, 2, 1. The loop ends when n > 0 becomes False.

For vs While

When to useforwhile
Count is known up frontYesOK
Walking through list / stringYesNo
Repeat until something changesNoYes
Risk of running foreverNoYes
An infinite loop happens when the while condition never becomes False. Always make sure the variable being tested actually changes inside the loop.

6. Putting It Together

Real programs combine all three patterns. A small login script is a good demo:

attempts = 0
while attempts < 3:           # iterative
    pwd = input("PWD: ")
    if pwd == "vm123":        # conditional
        print("Granted")
        break
    attempts += 1
else:
    print("Locked")               # sequential

The while drives repetition, if chooses what runs each round, the rest is plain sequential code.

Comparison at a Glance

AspectSequentialConditionalIterative
Block runsOnce0 or 1 time0 or many
Decided byPositionConditionCondition / count
Keywords(none)if/elif/elsefor, while
RiskForgotten stepWrong conditionInfinite loop

Quick Self-Test

For each phrase, identify the flow type:

  • "Read marks, compute total, print." → sequential
  • "If marks < 33 print Fail else Pass." → conditional
  • "Print Hello five times." → iterative
  • "Repeat asking until user types Y." → iterative
Three questions break down any task: Do I always do this? → sequential. Should I sometimes skip this? → conditional. Should I redo this? → iterative.

Chapter 13 Worksheet — Flow of Control (Introduction)

Total: 50 marks  |  Time: 75 min
Name: Class/Sec: Roll No.: Date:

Section A — Multiple Choice (1 × 10 = 10)

  1. The default flow of control in Python is:
    (a) Conditional(b) Iterative(c) Sequential(d) Random
  2. Python groups statements into a block using:
    (a) Curly braces(b) Indentation(c) Semicolons(d) BEGIN/END
  3. The standard indentation is:
    (a) 1 space(b) 2 spaces(c) 4 spaces(d) 8 spaces
  4. Which keyword starts a counted loop?
    (a) if(b) for(c) elif(d) repeat
  5. range(2, 10, 3) produces:
    (a) 2, 5, 8(b) 2, 5, 8, 11(c) 2, 4, 6, 8(d) 3, 6, 9
  6. An infinite loop is most likely with:
    (a) for(b) if(c) while(d) elif
  7. Which is NOT a flow-of-control pattern?
    (a) Sequential(b) Iterative(c) Conditional(d) Recursive
  8. Which line opens a block?
    (a) if x > 0;(b) if x > 0:(c) if x > 0 then(d) if x > 0 {
  9. How many branches of if-elif-else run per execution?
    (a) Zero(b) Exactly one(c) All matching(d) The first two
  10. Forgotten indent after for gives:
    (a) ValueError(b) NameError(c) IndentationError(d) Nothing

Section B — Find the Output (1 × 8 = 8)

  1. for i in range(3):
        print(i)
    Output:
  2. for i in range(1, 6, 2):
        print(i, end=" ")
    Output:
  3. n = 3
    while n > 0:
        print(n, end=" ")
        n -= 1
    Output:
  4. x = 7
    if x % 2 == 0:
        print("even")
    else:
        print("odd")
    Output:
  5. total = 0
    for i in range(1, 5):
        total += i
    print(total)
    Output:
  6. m = 80
    if m >= 90: g = "A"
    elif m >= 75: g = "B"
    else: g = "C"
    print(g)
    Output:
  7. for ch in "abc":
        print(ch * 2, end="-")
    Output:
  8. i = 1
    while i < 20:
        print(i, end=" ")
        i *= 2
    Output:

Section C — Find the Error (1 × 6 = 6)

Each snippet has exactly one error. Mark the line number and write the corrected line.

  1. 1  if x > 0
    2      print("+ve")
    Wrong line:   Correction:
  2. 1  for i in range(5):
    2  print(i)
    Wrong line:   Correction:
  3. 1  n = 5
    2  while n > 0:
    3      print(n)
    Wrong line:   Correction:
  4. 1  age = 20
    2  if age >= 18: print("vote")
    3  elseif age < 18: print("wait")
    Wrong line:   Correction:
  5. 1  m = 50
    2  if m >= 33: print("Pass")
    3  else m < 33: print("Fail")
    Wrong line:   Correction:
  6. 1  for i in range(1, 5):
    2      print(i)
    3   print("done")
    Wrong line:   Correction:

Section D — Short Answer (2 × 5 = 10)

  1. List the three patterns of flow of control with one Python keyword for each.
  2. Why is indentation important in Python? Give one example of an error caused by wrong indentation.
  3. Differentiate between a for loop and a while loop with one example each.
  4. What is meant by the Input → Process → Output structure? Show it for a program that prints simple interest.
  5. What is an infinite loop? Write one example and show how to avoid it.

Chapter 13 Worksheet — (continued)

Sheet 2 (Back)

Section E — Code Tasks (16 marks)

Each program should read input where required and produce a clear output. Use a separate sheet if you need more space.

  1. (2) Write a Python program that reads the radius of a circle and prints its area and circumference. Use A = 3.14 * r * r and C = 2 * 3.14 * r. (Pure sequential.)
  2. (3) Read a number and use if-elif-else to print whether it is positive, negative, or zero.
  3. (3) Use a for loop to print the multiplication table of any number entered by the user, from 1 to 10. Output format: 5 x 1 = 5, 5 x 2 = 10, …
  4. (2) Use a while loop to print the numbers from 10 down to 1 on one line, separated by spaces, followed by "Lift off!".
  5. (3) Read an integer n and print the sum of all even numbers from 1 to n (inclusive). Use a for loop.
  6. (3) Identify the flow-of-control pattern (sequential / conditional / iterative) used in each line below, and give a short reason.
    (i)   total = a + b
    (ii)  if n % 2 == 0: print("Even")
    (iii) for i in range(5): print(i)