🎓 Senior Secondary
| CBSE • Computer Science

Flow of Control in Python

If-else, for loop, while loop, break, continue.

1 Lesson 1 MCQ 1 Mnemonic
+30
XP
Available to earn
1
Lesson

Flow of Control in Python — Lesson

1) Hook — The Traffic Signal and Your Python Code

Imagine you are crossing a busy street in Mumbai. The traffic signal controls when you walk, stop, or wait. Similarly, in Python programming, flow of control decides which part of the code runs and when. Just like you don’t cross on a red light, Python doesn’t execute every line sequentially—it follows conditions and loops to control the “traffic” of your program.

2) Core Concepts — Understanding Flow of Control in Python

Flow of control determines the order in which individual statements, instructions, or function calls are executed or evaluated.

Python provides three main ways to control the flow of your program:

  • Conditional Statements — Make decisions using if, if-else, and if-elif-else.
  • Loops — Repeat actions using for and while loops.
  • Control Statements — Modify loop behavior with break, continue, and pass.
Conditional Statements

They allow your program to take decisions based on conditions.

Syntax Description Example
if condition:
    statement(s)
Executes statements if condition is True.
if marks >= 33:
print("Pass")
if condition:
    statement(s)
else:
    statement(s)
Executes one block if condition is True, else executes another.
if age >= 18:
print("Adult")
else:
print("Minor")
if condition1:
    statement(s)
elif condition2:
    statement(s)
else:
    statement(s)
Checks multiple conditions in sequence.
if marks >= 90:
print("A Grade")
elif marks >= 75:
print("B Grade")
else:
print("C Grade")
Loops

Loops help repeat a block of code multiple times.

Loop Type Syntax Example
for loop for variable in sequence:
    statement(s)
for i in range(1,6):
print(i)
while loop while condition:
    statement(s)
count = 1
while count <= 5:
print(count)
count += 1
Control Statements in Loops
  • break: Exits the loop immediately.
  • continue: Skips the current iteration and continues with the next.
  • pass: Does nothing; used as a placeholder.

Example:

for i in range(1, 6):
    if i == 3:
        break  # Loop stops when i is 3
    print(i)
  

3) Key Formulas/Rules

Rule 1: Indentation is mandatory in Python to define blocks under control statements.

Rule 2: if conditions must evaluate to True or False.

Rule 3: Use elif to check multiple conditions sequentially.

Rule 4: for loops iterate over a sequence like list, tuple, or range().

Rule 5: Use break to exit loops early and continue to skip to next iteration.

4) Did You Know?

Python was named after the British comedy group Monty Python — not the snake! Its creator, Guido van Rossum, wanted a name that was short, unique, and slightly mysterious. Just like Monty Python’s sketches, Python code is designed to be fun and readable.

5) Exam Tips — Common Mistakes & Board Exam Patterns

  • Indentation Errors: Always indent blocks under if, for, while, and else. Missing or inconsistent indentation leads to errors.
  • Colon (:): Don’t forget the colon at the end of control statements (e.g., if condition:).
  • Logical Conditions: Use correct operators like == for comparison, not = (assignment).
  • Loop Boundaries: Remember range(1,6) runs from 1 to 5, not 6.
  • Practice Writing: Previous CBSE questions often ask for writing programs using if-else and loops, or to trace output of given code.

Previous Year Question Pattern Examples:

  • Write a Python program to check if a student has passed or failed based on marks.
  • Trace the output of a loop that prints numbers from 1 to 10 but skips multiples of 3.
  • Write a program using if-elif-else to assign grades based on marks.
2
MCQ Practice

Flow of Control in Python — Mcq

3
Memory Trick

Flow of Control in Python — Mnemonic

Mnemonic 1: FLOW Control in Python – "IF, ELSE, LOOP, GO!" 🚦

  • IIF condition checks ✅
  • EELSE gives the alternative path 🔄
  • LLOOP repeats (for/while) 🔁
  • GGO to next statement after loop or condition ▶️

Remember: "If Else Loop Go, Python ka flow!" 😄

Mnemonic 2: Hindi Rhyming Trick for Flow Control 🐍

"Agar (If) socho, warna (Else) bolo, Jab tak (While) chale, tab tak (For) golo!"

  • Agar (If) – condition check karna
  • Warna (Else) – jab condition false ho
  • Jab tak (While) – repeat jab tak condition true
  • Tab tak (For) – fixed number baar repeat karna

Fun and easy to recall during exams! 😎

Mnemonic 3: Acronym "IFELOOP" for Python Control Flow 🔤

  • IIF (condition check)
  • FFOR loop (fixed iteration)
  • EELSE (alternate path)
  • LLOOP (general loops)
  • OOUTPUT after control flow
  • OOPTIONAL else-if (elif)
  • PPASS statement (do nothing)

Think: "I Feel Else Loop On Python!" 🐍

Interactive

Mission: Master This Topic!

Reinforce what you learned with fun activities

🎯

Ready to Battle? Test Your Knowledge!

Practice MCQs, build combos, climb the leaderboard!

Start Practice

Loading...

Hey! 🔥 Your 7-day streak is at risk. Complete one quick quest today?

Streak broken? No worries. Recover with bonus XP by completing a quest now.