On this page
A program that only runs line by line cannot decide or repeat anything. Flow of control is the chapter where Python learns to choose and to loop, and it sits under almost every program you will write in Class 11 and 12. This post covers what the syllabus lists, works through tested programs with their exact output, and shows how to trace a loop the way examiners expect.
What does the syllabus include?
The CBSE Computer Science curriculum for 2026-27 lists, for Class 11: flow of control, use of indentation, sequential, conditional and iterative flow; if, if-else and if-elif-else with flowcharts; and for loops, range(), while loops, break and continue, and nested loops. The suggested programs include absolute value, sorting three numbers, divisibility, patterns, summing a series and factorials. The Informatics Practices curriculum also lists if-else, if-elif-else, while and for in Class 11. The NCERT chapter is Flow of Control, Chapter 6 of the Class 11 Computer Science book.
How does an if-elif-else ladder decide?
Python checks the conditions from top to bottom and runs only the first block whose condition is True.
marks = 72
if marks >= 90:
grade = 'A'
elif marks >= 75:
grade = 'B'
elif marks >= 60:
grade = 'C'
else:
grade = 'D'
print(grade)This prints C. The test 72 >= 90 is False, 72 >= 75 is False, and 72 >= 60 is True, so Python stops there. If you put marks >= 60 first, a student with 95 would also get C, because that test is True and the later ones are never checked. Order elif conditions from the strictest to the loosest.
What does range() actually produce?
The Python tutorial notes that the end point given to range() is never part of the sequence.
list(range(5)) gives [0, 1, 2, 3, 4].
list(range(1, 10, 3)) gives [1, 4, 7].
list(range(10, 0, -3)) gives [10, 7, 4, 1].
Here is the factorial program, which needs range(1, n + 1) so that n itself is included:
n = 5
fact = 1
for i in range(1, n + 1):
fact = fact * i
print(fact)This prints 120, because 1 × 2 × 3 × 4 × 5 = 120. With range(1, n) you would get 24.
When should you use a while loop?
Use while when you do not know in advance how many times the loop will run. Summing the digits of a number is the classic case.
num = 1234
total = 0
while num > 0:
total = total + num % 10
num = num // 10
print(total)Trace it as a table. Pass 1: num % 10 is 4, so total = 4 and num = 123. Pass 2: total = 7, num = 12. Pass 3: total = 9, num = 1. Pass 4: total = 10, num = 0. Now num > 0 is False, the loop ends and 10 is printed. If you delete the line num = num // 10, num never changes and the loop never ends.
How do break, continue and nested loops work?
break leaves the innermost loop at once. continue skips the rest of the current pass and moves to the next one.
for k in range(1, 8):
if k == 5:
break
if k % 2 == 0:
continue
print(k, end=' ')This prints 1 3. The even values 2 and 4 are skipped, and the loop stops when k reaches 5, so 5, 6 and 7 never print. The Python tutorial also describes an else clause on loops, which runs only if no break happened. That clause is not in the CBSE list, so treat it as extra.
Nested loops print the syllabus patterns. The program below prints 12345, 1234, 123, 12 and 1 on separate lines:
for i in range(5, 0, -1):
for j in range(1, i + 1):
print(j, end='')
print()Why do beginners struggle with loops?
A review of research on introductory programming by Qian and Lehman (2017) found that students' difficulties fall into three kinds of knowledge: syntax, concepts and strategy. Among the factors the review lists are unfamiliar syntax, natural language, maths knowledge and inaccurate mental models of how a program runs. With loops, that can look like confusing = with ==, reading "while" in its everyday sense, or not picturing how a variable changes on each pass. Tracing tables target that mental model directly.
Common errors and how to avoid them
IndentationError, or a statement in the wrong block. NCERT stresses that Python checks indentation strictly. Use four spaces for each level and do not mix tabs with spaces.
Off-by-one with range(). Ask "is the end value included?" The answer is always no.
= in a condition. if x = 5 is a syntax error. Use ==.
Infinite while loops. Check that something inside the loop moves the condition towards False.
elif order. Put the strictest test first.
A practice routine
Daily, 15 minutes: trace two loops on paper with a variable table, then run them to check.
Three times a week: write one suggested program from the syllabus without notes, such as a pattern, a series sum or a factorial.
Weekly: take a working program and break it on purpose (change the indentation, the range end or the update line), then predict the error before you run it.
If a program's logic, rather than its syntax, keeps tripping you, Fermi's AI tutor can work out what you already know and build a plan for the session. Next, loops meet data structures in our guide to lists, tuples and dictionaries in Python.
Today, trace the digit-sum loop above for num = 907 on paper, then run it to check your table.



