Sequential Flow and Why Indentation Is Syntax
Quick answer Python runs statements top to bottom by default, and marks every block of code with indentation instead of braces, which makes a stray space a real error and a mis-indented line a silent bug.
Every program is a list of instructions. Flow of control means the order in which those instructions actually run when you press Run. Python's default order is the simplest one possible: top to bottom, one line after another, each line exactly once. That is called sequential flow.
Worked example 1 — pure sequential flow
price = 250
qty = 3
total = price * qty
print("Total bill = Rs", total)
print("Thank you")
Real output:
Total bill = Rs 750
Thank you
Five lines, five steps, in that order. Nothing is skipped and nothing repeats. But a real program has to make decisions ("if the balance is low, warn the user") and repeat work ("print the table of 7, ten lines"). So Python gives you two more kinds of flow.
| Kind of flow | What it does | Statements used |
|---|---|---|
| Sequential | Runs every statement once, in written order | plain statements |
| Conditional (selection) | Chooses which block to run, based on a condition | if, if-else, if-elif-else |
| Iterative (repetition) | Runs the same block again and again | for, while |
Worked example 2 — all three flows in one program
fare = 0 # sequential
for stop in range(1, 4): # iterative
fare = fare + 120 # inside the loop body
if fare > 200: # conditional, nested inside the loop
print("Stop", stop, "-> fare Rs", fare, "(above Rs 200)")
else:
print("Stop", stop, "-> fare Rs", fare)
print("Final fare = Rs", fare) # sequential again
Real output:
Stop 1 -> fare Rs 120
Stop 2 -> fare Rs 240 (above Rs 200)
Stop 3 -> fare Rs 360 (above Rs 200)
Final fare = Rs 360
Indentation is not decoration. In Python it is syntax. C, C++ and Java mark a block with braces { }, and indentation there is only for looks — you can delete every space and the program still compiles. Python threw the braces away and promoted the indentation itself to be the block marker. The gain is that ugly, misleading layout cannot exist: what your eye sees is exactly what the interpreter sees. The price is that a single stray space is an error.
The rules are short:
- A header line (
if,elif,else,for,while) must end with a colon:. - The statements belonging to that header — its block or suite — must be indented further than the header.
- Every line of one block must be indented by exactly the same amount.
- The block ends at the first line that goes back to a smaller indentation.
- Use 4 spaces per level. Never mix tabs and spaces.
Worked example 3 — the error you will meet on day one. Saved as demo.py:
marks = 82
if marks >= 33:
print("Pass")
Real output:
File "demo.py", line 3
print("Pass")
^^^^^
IndentationError: expected an indented block after 'if' statement on line 2
The colon promised a block, and no block arrived. The opposite mistake gives the opposite message:
total = 0
total = total + 5
print(total)
File "demo.py", line 2
total = total + 5
IndentationError: unexpected indent
And if you indent one line with a Tab key and the next with the space bar inside the same block:
if True:
print("this line uses a TAB")
print("this line uses 8 SPACES")
File "demo.py", line 3
print("this line uses 8 SPACES")
TabError: inconsistent use of tabs and spaces in indentation
Python 3 refuses to guess how wide your Tab is, so it stops. Set your editor to "insert spaces" once and you will never see this again.
Worked example 4 — the dangerous one: no error, wrong answer
These two versions differ by four spaces on one line. Both run cleanly. They do different things.
# Version A - the second print is INSIDE the if block
marks = 20
if marks >= 33:
print("Pass")
print("Report card printed")
print("--- A over ---")
# Version B - the second print is OUTSIDE the if block
marks = 20
if marks >= 33:
print("Pass")
print("Report card printed")
print("--- B over ---")
Real output:
--- A over ---
Report card printed
--- B over ---
Version A printed nothing for a failing student, which is right. Version B printed "Report card printed" for a student who scored 20, which is wrong — because that line is no longer part of the if. This is the single most common Python bug in Class 11 practicals, and no error message will warn you.
One more small thing: a block can never be empty. If you want a block that does nothing yet, use the pass statement.
attendance = 0
if attendance == 0:
pass # to be filled in later
else:
print("Present")
print("Program continues")
Real output:
Program continues- Default flow is sequential — top to bottom, each statement once; conditional and iterative statements exist to break that default.
- A header line always ends with a colon, and the indented block under it is its body. Both are compulsory.
- Every line of one block must carry exactly the same indentation; 4 spaces per level is the standard.
- Shifting a line in or out by four spaces changes the meaning of the program without producing any error — this is the classic silent bug.
- Missing indent gives IndentationError: expected an indented block; extra indent gives unexpected indent; mixing tab and space gives TabError.
