CLASS 11 — INFORMATICS PRACTICES
CBSE Board Notes
CHAPTER 5
Control Flow Statements
SECTION 1 — Types of Control Flow Statements
What is Control Flow?
By default, Python executes statements one by one from top to bottom — this is called Sequential
Execution. But real-world programs need to make decisions and repeat actions. Control Flow
Statements allow the programmer to control the order in which statements are executed.
Real-Life Analogy:
Think of a control flow statement like a traffic signal on a road. Without signals (control
flow), every car (statement) just goes straight. With signals, cars can be stopped,
redirected, or allowed to go in loops.
Python has 3 types of Control Flow Statements:
Type What it does Python Keywords
Sequential Statements Execute statements one by one, top to (Default — no keyword
bottom needed)
Conditional Make decisions — execute code only if, elif, else
Statements when a condition is True
Iterative Statements Repeat a block of code multiple times for, while
(loops)
1a. Sequential Statements
Sequential Statements
In sequential execution, Python reads the program from the very first line and executes each
statement one by one in the order they are written. There is no skipping, no repeating, and no
branching.
# Sequential execution — each line runs one after the other
name = "Sneha"
age = 16
school = "Delhi Public School"
print("Name:", name)
print("Age:", age)
print("School:", school)
Name: Sneha
Age: 16
School: Delhi Public School
START
|
v
Statement 1 (name = "Sneha")
|
v
Statement 2 (age = 16)
|
v
Statement 3 (print ...)
|
v
END
1b. Conditional Statements
Conditional Statements
Conditional statements allow Python to make decisions. A block of code is executed only if a specific
condition is True. If the condition is False, that block is skipped.
Real-Life Analogy:
When you check your exam result — IF you passed, you celebrate. ELSE you study harder.
The action depends on the condition (pass/fail).
• The if statement
• The if-else statement
• The if-elif-else statement
• Nested if statement
1c. Iterative Statements (Loops)
Iterative Statements (Loops)
Iterative statements (loops) allow Python to execute a block of code repeatedly — either a fixed
number of times or as long as a condition is True. Without loops, we would have to write the same
code hundreds of times.
Real-Life Analogy:
A washing machine runs its wash cycle 3 times automatically. You do not press the button 3
separate times — the machine loops. Similarly, a for loop repeats the code for you.
• The for loop — used when you know HOW MANY times to repeat
• The while loop — used when you repeat as long as a condition is True
SECTION 2 — Indentation in Python
What is Indentation?
Indentation means adding spaces or tabs at the beginning of a line to show that it belongs to a
particular block of code. In Python, indentation is NOT optional — it is MANDATORY and part of the
language syntax.
Why is Python different from other languages?
In languages like C, C++, and Java, curly braces { } are used to define blocks of code. In
Python, indentation REPLACES curly braces. Python uses the position of code to
understand which statements belong to which block.
Rules for Indentation in Python:
• Use 4 spaces per indentation level (this is the standard/recommended style)
• All statements inside a block must have the SAME level of indentation
• The first line of a block is always a header line ending with a colon ( : )
• Never mix tabs and spaces — this causes IndentationError
• Decreasing indentation means the block has ended
Correct vs Incorrect Indentation
CORRECT — Proper indentation
x = 10
if x > 5: # header line ends with :
print("Greater") # 4 spaces — inside the if block
print("than 5") # 4 spaces — still inside the if block
print("Done") # 0 spaces — outside the if block
Greater
than 5
Done
WRONG — Inconsistent indentation
x = 10
if x > 5:
print("Greater")
print("than 5") # ERROR: 2 spaces instead of 4!
# IndentationError: unindent does not match any outer indentation level
Understanding Indentation Levels:
# Level 0 — no indentation (main program)
x = 10
if x > 0:
# Level 1 — 4 spaces (inside if)
print("Positive")
if x > 5:
# Level 2 — 8 spaces (inside nested if)
print("Greater than 5")
# Back to Level 0
print("Program ends")
SECTION 3 — Conditional / Decision Making Statements
Conditional Statements
Conditional statements are used to execute specific blocks of code based on whether a condition is
True or False. The condition is always a Boolean expression (evaluates to True or False).
3a. The if Statement
The if Statement
The if statement is the simplest decision-making statement. The body (indented block) is executed
ONLY if the condition is True. If the condition is False, the body is completely skipped.
Syntax:
if condition:
statement 1
statement 2
...
Note: The condition must be followed by a colon ( : ). All statements inside the if block must
be indented by 4 spaces.
START
|
v
+--------+--------+
| condition ? |
+--------+--------+
| |
True False
| |
v v
Execute (skip
if-block block)
| |
+--------+
|
v
Next Statement
|
v
END
Example 1 — Check if a number is positive
num = int(input("Enter a number: "))
if num > 0:
print(num, "is a Positive number")
print("Great choice!")
print("Program finished") # this always runs
Enter a number: 8
8 is a Positive number
Great choice!
Program finished
Example 2 — Check eligibility to vote
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
print("Please register at your nearest booth.")
print("Thank you for checking!") # always runs
Enter your age: 20
You are eligible to vote.
Please register at your nearest booth.
Thank you for checking!
Example 3 — Check divisibility
n = int(input("Enter a number: "))
if n % 2 == 0:
print(n, "is an Even number")
if n % 5 == 0:
print(n, "is divisible by 5")
Enter a number: 10
10 is an Even number
10 is divisible by 5
Key Points about the if Statement:
• The condition can be any expression that evaluates to True or False
• You can have multiple independent if statements — each checks its own condition
• If the condition is False, Python silently skips the entire if block
• The if block ends when indentation decreases back to the level of the if keyword
3b. The if-else Statement
The if-else Statement
The if-else statement provides TWO paths — one for when the condition is True (if block) and
another for when the condition is False (else block). Exactly ONE of the two blocks will always
execute.
Syntax:
if condition:
# block executed when condition is True
statement(s)
else:
# block executed when condition is False
statement(s)
Note: else does not have any condition. It automatically catches all cases where the if
condition was False.
START
|
v
+--------+--------+
| condition ? |
+--------+--------+
| |
True False
| |
v v
Execute Execute
if-block else-block
| |
+--------+
|
v
Next Statement
|
v
END
Example 1 — Check even or odd
n = int(input("Enter a number: "))
if n % 2 == 0:
print(n, "is an Even number")
else:
print(n, "is an Odd number")
Enter a number: 7
7 is an Odd number
Example 2 — Pass or Fail
marks = int(input("Enter your marks (out of 100): "))
if marks >= 40:
print("Congratulations! You have PASSED.")
print("Your marks:", marks)
else:
print("Sorry, you have FAILED.")
print("Marks needed to pass: 40")
Enter your marks (out of 100): 35
Sorry, you have FAILED.
Marks needed to pass: 40
Example 3 — Check if a year is a leap year
year = int(input("Enter a year: "))
if year % 4 == 0:
print(year, "is a Leap Year")
else:
print(year, "is NOT a Leap Year")
Enter a year: 2024
2024 is a Leap Year
Example 4 — Find greater of two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print(a, "is greater")
else:
print(b, "is greater")
Enter first number: 15
Enter second number: 28
28 is greater
3c. The if-elif-else Statement
The if-elif-else Statement
When there are MORE THAN TWO conditions to check, we use elif (short for 'else if'). Python checks
conditions from top to bottom and executes the FIRST block whose condition is True. All remaining
blocks are skipped. The else block runs only if NONE of the conditions are True.
Syntax:
if condition_1:
statement(s) # runs if condition_1 is True
elif condition_2:
statement(s) # runs if condition_2 is True
elif condition_3:
statement(s) # runs if condition_3 is True
else:
statement(s) # runs if ALL conditions above are False
START
|
v
[condition_1 ?]---True---> Execute Block 1 ---+
| |
False |
v |
[condition_2 ?]---True---> Execute Block 2 ---+
| |
False |
v |
[condition_3 ?]---True---> Execute Block 3 ---+
| |
False |
v |
Execute else Block --------------------------->+
|
v
Next Statement
Example 1 — Grade System
marks = int(input("Enter marks (out of 100): "))
if marks >= 90:
print("Grade: A+ — Outstanding!")
elif marks >= 80:
print("Grade: A — Excellent!")
elif marks >= 70:
print("Grade: B — Very Good!")
elif marks >= 60:
print("Grade: C — Good")
elif marks >= 40:
print("Grade: D — Pass")
else:
print("Grade: F — Fail")
Enter marks (out of 100): 83
Grade: A — Excellent!
Example 2 — Positive, Negative, or Zero
num = int(input("Enter a number: "))
if num > 0:
print(num, "is Positive")
elif num < 0:
print(num, "is Negative")
else:
print("The number is Zero")
Enter a number: -5
-5 is Negative
Example 3 — Day of the week
day = int(input("Enter day number (1-7): "))
if day == 1:
print("Monday")
elif day == 2:
print("Tuesday")
elif day == 3:
print("Wednesday")
elif day == 4:
print("Thursday")
elif day == 5:
print("Friday")
elif day == 6:
print("Saturday")
elif day == 7:
print("Sunday")
else:
print("Invalid day number! Enter 1-7.")
3d. Nested if Statements
Nested if Statements
A nested if is an if statement written inside another if (or elif/else) block. It is used when a second
condition needs to be checked only after the first condition is True.
Real-Life Analogy:
To board an international flight: First check — Do you have a valid passport? If YES,
second check — Do you have a valid visa? Both checks must pass before boarding.
Syntax:
if condition_1:
# outer if block
if condition_2:
# nested if block (runs only if both conditions are True)
statement(s)
else:
statement(s)
else:
statement(s)
Example 1 — Find largest of three numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b:
if a >= c:
print(a, "is the largest")
else:
print(c, "is the largest")
else:
if b >= c:
print(b, "is the largest")
else:
print(c, "is the largest")
Enter first number: 10
Enter second number: 35
Enter third number: 22
35 is the largest
Example 2 — Eligibility for a scholarship
marks = int(input("Enter marks: "))
attendance = int(input("Enter attendance %: "))
if marks >= 85:
if attendance >= 75:
print("Eligible for scholarship!")
else:
print("Marks are good, but attendance is insufficient.")
else:
print("Marks are below the required cutoff (85).")
Summary — Comparison of all Conditional Statements:
Statement When to Use Blocks Both/All/One block
runs?
if One condition to check if if block runs only when
True
if-else Two outcomes — True or if, else Exactly ONE always runs
False
if-elif-else Multiple conditions (3 or if, elif(s), else Only the FIRST True block
more) runs
Nested if A second check after first if inside if Depends on both
is True conditions
SECTION 4 — Iterative Statements: The for Loop
What is a Loop?
A loop is used to execute a block of code multiple times without writing it again and again. Loops
save time and make programs shorter and more powerful.
Without loop — Printing 1 to 5:
print(1) # line 1
print(2) # line 2
print(3) # line 3
print(4) # line 4
print(5) # line 5
# Imagine doing this for 1 to 1000!
With for loop — Printing 1 to 5 in ONE loop:
for i in range(1, 6):
print(i)
# Just 2 lines — works for 1 to 1,000,000 too!
4a. The for Loop — Syntax and Basics
The for Loop
The for loop in Python is used to iterate over a sequence (like a list, tuple, string, or range) and
execute the loop body once for each item in the sequence.
Syntax:
for variable in sequence:
statement 1
statement 2
...
• variable — the loop variable, it takes each value from the sequence one by one
• sequence — can be a range, list, tuple, string, or any iterable
• The loop body (indented block) runs once for each value in the sequence
START
|
v
Set variable = first item in sequence
|
v
[More items left in sequence?]
| |
Yes No
| |
v v
Execute loop body END
|
Set variable = next item in sequence
|
+-------> (back to check: more items?)
4b. The range() Function
The range() Function
The range() function is the most commonly used tool with for loops. It generates a sequence of
numbers which the for loop can iterate over.
Form Syntax Generates Example Output
1 argument range(stop) 0, 1, 2, ... stop-1 range(5) → 0 1 2 3
4
2 arguments range(start, stop) start, start+1, ... stop-1 range(2,6) → 2 3 4
5
3 arguments range(start, stop, step) start, start+step, ... stop-1 range(1,10,2) → 1 3
579
Examples of range()
# range(stop) — starts from 0
for i in range(5):
print(i, end=" ")
# Output: 0 1 2 3 4
# range(start, stop) — starts from start
for i in range(1, 6):
print(i, end=" ")
# Output: 1 2 3 4 5
# range(start, stop, step) — custom step
for i in range(0, 11, 2):
print(i, end=" ")
# Output: 0 2 4 6 8 10
# Negative step — counting backwards
for i in range(10, 0, -1):
print(i, end=" ")
# Output: 10 9 8 7 6 5 4 3 2 1
# Note: range() does NOT include the stop value (stop is excluded)
# range(1, 5) gives: 1, 2, 3, 4 (NOT 5)
4c. for Loop — Iterating over Different Sequences
Iterating over Different Sequences
(i) Iterating over a String
A for loop can go through each character of a string one by one.
name = "Python"
for ch in name:
print(ch, end=" ")
P y t h o n
(ii) Iterating over a List
A for loop can process each item of a list.
fruits = ["Apple", "Banana", "Mango", "Orange"]
for fruit in fruits:
print("Fruit:", fruit)
Fruit: Apple
Fruit: Banana
Fruit: Mango
Fruit: Orange
(iii) Iterating over a Tuple
marks = (85, 90, 78, 92, 88)
total = 0
for m in marks:
total = total + m
print("Total Marks:", total)
print("Average:", total / len(marks))
Total Marks: 433
Average: 86.6
(iv) Iterating over a Dictionary
student = {"name": "Ravi", "age": 16, "marks": 91}
# Loop over keys
for key in student:
print(key, ":", student[key])
name : Ravi
age : 16
marks : 91
4d. for Loop — Practical Programs
Practical Programs using for Loop
Program 1 — Print multiplication table
n = int(input("Enter a number: "))
print(f"Multiplication Table of {n}")
print("-" * 25)
for i in range(1, 11):
result = n * i
print(f"{n} x {i:2} = {result:3}")
Enter a number: 7
Multiplication Table of 7
-------------------------
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
Program 2 — Sum of first n natural numbers
n = int(input("Enter n: "))
total = 0
for i in range(1, n + 1):
total = total + i
print(f"Sum of first {n} natural numbers = {total}")
Enter n: 10
Sum of first 10 natural numbers = 55
Program 3 — Factorial of a number
n = int(input("Enter a number: "))
factorial = 1
for i in range(1, n + 1):
factorial = factorial * i
print(f"Factorial of {n} = {factorial}")
Enter a number: 5
Factorial of 5 = 120
Program 4 — Print all even numbers from 1 to n
n = int(input("Enter n: "))
print("Even numbers from 1 to", n, ":")
for i in range(2, n + 1, 2):
print(i, end=" ")
Enter n: 20
Even numbers from 1 to 20 :
2 4 6 8 10 12 14 16 18 20
Program 5 — Count vowels in a string
text = input("Enter a string: ")
count = 0
vowels = "aeiouAEIOU"
for ch in text:
if ch in vowels:
count = count + 1
print("Number of vowels:", count)
Enter a string: Informatics Practices
Number of vowels: 7
Program 6 — Print a star pattern
n = int(input("Enter number of rows: "))
for i in range(1, n + 1):
print("* " * i)
Enter number of rows: 5
*
* *
* * *
* * * *
* * * * *
4e. Nested for Loops
Nested for Loops
A nested for loop is a for loop written inside another for loop. The inner loop completes ALL its
iterations for each SINGLE iteration of the outer loop.
Real-Life Analogy:
A clock — the minute hand completes a full round (60 iterations) for every single move of
the hour hand. Outer loop = hour hand, Inner loop = minute hand.
# Nested loop to print multiplication table (2 to 4)
for i in range(2, 5): # outer loop: table number
print(f"Table of {i}:")
for j in range(1, 6): # inner loop: multiplier 1 to 5
print(f" {i} x {j} = {i*j}")
print() # blank line after each table
Table of 2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
Table of 3:
3 x 1 = 3
...
4f. else Clause with for Loop
else Clause with for Loop
Python uniquely allows an else block to be attached to a for loop. The else block executes ONLY
AFTER the loop has completed all its iterations normally. If the loop is stopped early by a break
statement, the else block does NOT run.
for i in range(1, 6):
print(i)
else:
print("Loop completed successfully!")
1
2
3
4
5
Loop completed successfully!
When does the else run?
• else RUNS when — the for loop finishes all items without being interrupted
• else does NOT RUN when — a break statement exits the loop early
4g. Loop Control: break, continue, pass
Loop Control Statements
(i) break Statement
The break statement immediately exits the loop — no more iterations happen. Program control
moves to the statement after the loop.
# Find first number divisible by 7 between 1 and 50
for i in range(1, 51):
if i % 7 == 0:
print("First number divisible by 7:", i)
break # exit the loop immediately
print("Search done")
First number divisible by 7: 7
Search done
(ii) continue Statement
The continue statement skips the REST of the current iteration and jumps to the next iteration. The
loop does NOT exit — it just skips that one step.
# Print all numbers from 1 to 10 EXCEPT multiples of 3
for i in range(1, 11):
if i % 3 == 0:
continue # skip this iteration
print(i, end=" ")
1 2 4 5 7 8 10
(iii) pass Statement
The pass statement does nothing — it is a placeholder. It is used when a block of code is
syntactically required but you have nothing to write there yet.
# pass as placeholder — code to be written later
for i in range(5):
pass # do nothing for now
print("Loop ran (but did nothing inside)") # this runs
Loop ran (but did nothing inside)
Keyword What it does Loop ends? Example use
break Exits the loop immediately YES Stop when target is found
continue Skips current iteration, NO Skip even/odd numbers
moves to next
pass Does nothing — empty NO Future code placeholder
placeholder
Practice Questions — Chapter 5
Section A — Easy (1 Mark Each)
Q1 Name the three types of Control Flow Statements in Python. 1M
Q2 What is indentation in Python? Is it optional or mandatory? 1M
Q3 What is the output of range(2, 10, 3) ? List all values. 1M
Q4 What keyword is used to skip the current iteration of a loop? 1M
Q5 Write the output: for i in range(1, 6): print(i * 2, end=' ') 1M
Q6 What is the difference between break and continue? 1M
Q7 How many times does else run in a for-else if no break occurs? 1M
Q8 What error is raised if indentation is incorrect in Python? 1M
Section B — Medium (2–3 Marks Each)
What are Sequential, Conditional and Iterative statements? Give one real-life
Q9 3M
example of each.
Explain the if-elif-else statement with syntax. Write a Python program to check
Q10 3M
whether a given number is positive, negative, or zero.
Explain the three forms of the range() function with examples: (a) range(stop)
Q11 3M
(b) range(start, stop) (c) range(start, stop, step)
Write a Python program using a for loop to find the sum of all odd numbers
Q12 2M
between 1 and 100.
Write the output of the following code: for i in range(1, 10): if i % 2 == 0:
Q13 3M
continue if i == 7: break print(i, end=' ')
Write a Python program using nested if to find the largest of three numbers
Q14 3M
entered by the user.
What is a nested for loop? Write a program to print the following pattern: * * * *
Q15 3M
***********
Section C — Hard / Application Based (4–5 Marks)
Write a Python program that: (a) Takes a number n from the user (b) Uses a
Q16 for loop to print its multiplication table from 1 to 10 (c) Highlights multiples that 4M
are even by printing ' ← EVEN' after them
Explain with a neat flowchart (text-based) and program the complete working of
Q17 the if-elif-else grade system: A+: marks >= 90, A: >= 80, B: >= 70, C: >= 60, 5M
D: >= 40, F: below 40
A shop gives discounts based on purchase amount: - Above Rs.5000: 20%
discount - Rs.3000-Rs.5000: 15% discount - Rs.1000-Rs.2999: 10% discount -
Q18 5M
Below Rs.1000: No discount Write a Python program to calculate and display
the final bill amount.
Write a Python program using a for loop to: (a) Accept 5 subject marks from
the user one by one (b) Calculate total and percentage (c) Display grade based
Q19 5M
on percentage using if-elif-else (d) Tell whether the student is Pass or Fail
(passing marks = 40 per subject)
Trace the following code and predict the exact output. Explain each step: n =
15 for i in range(1, n+1): if i % 3 == 0 and i % 5 == 0: print("FizzBuzz")
Q20 5M
elif i % 3 == 0: print("Fizz") elif i % 5 == 0: print("Buzz") else:
print(i)
End of Chapter 5 Notes
Prepared by: Shivam Gupta (PGT — IP/CS) | CBSE Class 11