Flow of Control Class 11: Conditional Statements, Loops, break and continue in Python
Updated 14 October 2026 · Fact-checked
Flow of Control decides the order in which Python statements run. In CBSE Class 11 Computer Science you learn indentation, sequential flow, the if, if-else and if-elif-else statements, for loops with range(), while loops, break and continue, and nested loops, and use them to write programs for absolute value, sorting three numbers, patterns, series sums and factorials.
What Flow of Control is about
This chapter is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam. Loops and conditions appear in almost every program after this, so output-prediction and program-writing questions lean heavily on it.
The 2026-27 syllabus lists: use of indentation, sequential, conditional and iterative flow; if, if-else, if-elif-else with flowcharts and simple programs (absolute value, sorting 3 numbers, divisibility of a number); for loop, range(), while loop, flowcharts, break and continue, nested loops, and suggested programs for generating patterns, summation of series and factorial of a positive number.
Working rule for this chapter: before predicting any output, write a small trace table with one column per variable and one row per pass of the loop. Every program and output below has been run in Python 3.
Weightage: This chapter is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam together with Introduction to Problem Solving, Getting Started with Python, Strings, Lists, Tuples and Dictionaries and Introduction to Python Modules.Source: CBSE Computer Science (083) syllabus 2026-27, Class XI distribution of marks, Unit II Computational Thinking and Programming - 1
Key concepts
- Sequential flow and indentation
- NCERT section NCERT 6.1, 6.3
By default statements run one after another from top to bottom: this is sequential flow. Conditional flow chooses between blocks; iterative flow repeats a block.
Python marks a block (the statements controlled by an if, else, for or while) by indentation: the same number of leading spaces for every statement in the block (4 spaces is the usual choice). The line that starts the block ends with a colon (:). Lines after the block return to the earlier indentation. Wrong or inconsistent indentation gives an IndentationError (a syntax error), or, worse, a logical error when a statement ends up inside or outside a block by mistake. Other languages use braces { } for blocks; Python uses indentation alone.
Worked example
How many times is 'Done' printed in each case?
(a)
for i in range(3):
print(i)
print('Done')
(b)
for i in range(3):
print(i)
print('Done')Try it first, then show the solutionSolution
- In (a) print('Done') is indented, so it is inside the loop: it runs on each of the 3 passes.
- In (b) it is outside the loop: it runs once after the loop ends.
Answer: (a) 3 times (b) once.
- if, if-else and if-elif-else
- NCERT section NCERT 6.2
if: runs a block only when a condition is True.
if condition: statementsif-else: runs one of two blocks: the if block when the condition is True, the else block otherwise.
if-elif-else: tests conditions in order; the block of the first True condition runs and the rest are skipped; else runs if none is True. There can be any number of elif parts, and else is optional.The order of elif conditions matters: put the most specific (or highest) range first. Conditions can be combined with and, or and not. An if can also contain another if (nested if). In a flowchart each condition is a diamond with True and False exits.
Worked example
Find the output for marks = 85:
marks = 85 if marks >= 33: print('Pass') if marks >= 90: print('A1') elif marks >= 80: print('A2') elif marks >= 70: print('B1') else: print('Below B1')Try it first, then show the solutionSolution
- The first if is a separate statement: 85 >= 33, so 'Pass' is printed.
- In the if-elif chain, 85 >= 90 is False; 85 >= 80 is True, so 'A2' is printed and the rest is skipped.
Answer: Pass
A2- Simple decision programs: absolute value, sorting three numbers, divisibility
- NCERT section NCERT 6.2 and syllabus suggested programs
These three programs are named in the syllabus.
- Absolute value: if n < 0, make it -n; otherwise keep n. (Python also has the built-in abs().)
- Sorting three numbers: compare pairs and swap so that the smallest moves first. Three comparisons are enough: (a, b), then (a, c), then (b, c).
- Divisibility: n is divisible by d when n % d == 0. Combine tests with and/or, e.g. divisible by both 3 and 5 means n % 3 == 0 and n % 5 == 0 (that is, by 15).
Worked example
Write a program that sorts a = 42, b = 7, c = 19 into ascending order using only if statements and swaps, and give the output.
Try it first, then show the solutionSolution
a, b, c = 42, 7, 19 if a > b: a, b = b, a if a > c: a, c = c, a if b > c: b, c = c, b print(a, b, c)- After (a, b): 7, 42, 19. (a, c): 7 < 19, no swap. (b, c): 42 > 19, swap: 7, 19, 42.
Answer: 7 19 42
- The for loop and range()
- NCERT section NCERT 6.4.1 (A), (B)
A for loop takes each item of a sequence (string, list, tuple, range) in turn and runs its block once per item:
for variable in sequence: statementsrange([start,] stop[, step]) produces integers from start (default 0) up to but not including stop, increasing by step (default 1). The step may be negative to count down, but never 0.
- range(5) → 0, 1, 2, 3, 4
- range(2, 10, 3) → 2, 5, 8
- range(10, 0, -2) → 10, 8, 6, 4, 2
- range(5, 1) → nothing (start is already past stop)
The number of values in range(start, stop, step) with a positive step is the number of terms of start, start + step, ... that stay below stop. Use a for loop when the number of repetitions is known in advance.
Worked example
Give the output:
print(list(range(3, 15, 4))) print(list(range(9, 0, -3))) for ch in 'Py': print(ch * 2, end=' ')Try it first, then show the solutionSolution
- 3, 7, 11 (15 is not reached).
- 9, 6, 3 (0 is excluded).
- For each character, print it twice followed by a space.
Answer: [3, 7, 11]
[9, 6, 3]
PP yy- The while loop
- NCERT section NCERT 6.4.2
A while loop repeats its block as long as a condition is True. The condition is tested before each pass, so the block may run zero times.
while condition: statementsSomething inside the loop must eventually make the condition False, or the loop never ends: an infinite loop, which is a logical error. Use while when the number of repetitions is not known in advance: reading input until a sentinel value, processing the digits of a number, repeating until a target is reached.
Worked example
Write a while loop to reverse the digits of 4072 and give its output.
Try it first, then show the solutionSolution
n = 4072 rev = 0 while n > 0: rev = rev * 10 + n % 10 n = n // 10 print(rev)- Trace: (n, rev) = (4072, 0) → (407, 2) → (40, 27) → (4, 270) → (0, 2704).
Answer: 2704
- break and continue
- NCERT section NCERT 6.5
break ends the innermost loop at once; control moves to the first statement after that loop. Use it to stop searching once the answer is found.
continue skips the rest of the current pass and goes straight to the next pass (the next item in a for loop, or the condition test in a while loop). Use it to ignore some items.
In a while loop, make sure continue does not skip the statement that updates the loop variable, or the loop may become infinite.
Worked example
Give the output:
for n in range(1, 10): if n % 3 == 0: continue if n == 8: break print(n, end=' ')Try it first, then show the solutionSolution
- 1, 2 printed; 3 skipped (continue); 4, 5 printed; 6 skipped; 7 printed.
- At 8 the loop breaks, so 8 and 9 are never printed.
Answer: 1 2 4 5 7
- Nested loops and patterns
- NCERT section NCERT 6.6
A loop inside another loop is a nested loop. For every single pass of the outer loop, the inner loop runs completely. If the outer loop runs m times and the inner n times, the inner block runs m × n times.
For patterns, the outer loop usually controls the rows and the inner loop the columns (what is printed on each row). Print items on the same row with end='' or end=' ' and move to the next row with an empty print().
Worked example
Write a program to print:
1
1 2
1 2 3
1 2 3 4Try it first, then show the solutionSolution
- Row i (1 to 4) prints the numbers 1 to i.
for i in range(1, 5): for j in range(1, i + 1): print(j, end=' ') print()
Answer: 1
1 2
1 2 3
1 2 3 4 (each row ends with a space, invisible on screen)- Series, factorial and other loop programs
- NCERT section Syllabus suggested programs; NCERT 6.4
Common loop patterns:
- Accumulator (sum or product): start with total = 0 (for a sum) or product = 1 (for a product), then update in the loop.
- Factorial of a positive n: n! = 1 × 2 × ... × n; 0! = 1.
- Series: write the general term with the loop variable, e.g. 1 + x + x² + ... + xⁿ has term xi; 1 - 2 + 3 - 4 ... has term i * (-1)(i + 1).
- Counter: count = 0, then count += 1 when a condition holds.
- Prime test: count the divisors, or break as soon as one is found.
Worked example
Write a program to find 6! and the sum 1 + 1/2 + 1/3 + ... + 1/6 (to 3 decimal places).
Try it first, then show the solutionSolution
n = 6 fact = 1 s = 0 for i in range(1, n + 1): fact = fact * i s = s + 1 / i print(fact, round(s, 3))- fact: 1, 2, 6, 24, 120, 720. s = 1 + 0.5 + 0.333 + 0.25 + 0.2 + 0.1667 = 2.45.
Answer: 720 2.45
Flow of Control in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
if-elif-else for slabs
Suppose a cinema charges ₹100 for children under 12, ₹200 for adults from 12 to 59 and ₹120 for seniors aged 60 or more.
Write the if-elif-else block and give the ticket price for ages 12 and 60.
Try it first, then show the solutionSolution
- if age < 12: price = 100
elif age < 60: price = 200
else: price = 120 - Age 12 is not < 12 but is < 60: ₹200. Age 60 fails both: ₹120.
Answer: ₹200 for 12 and ₹120 for 60.
Memory hook: Test the boundary ages in every slab question.
while loop with an unknown count
Imagine you save ₹500 in the first month and increase your saving by ₹100 every month, and you want to know how many months it takes for the total to reach ₹5000.
Use a while loop idea to find the number of months.
Try it first, then show the solutionSolution
- Monthly savings: 500, 600, 700, 800, 900, 1000 → running totals 500, 1100, 1800, 2600, 3500, 4500.
- Month 7 adds 1100: total 5600 ≥ 5000, so the loop stops.
Answer: 7 months (total ₹5600).
Memory hook: while = repeat until the target is met, count unknown.
break in a search
Suppose a librarian checks a shelf of 200 books one by one for a lost book that turns out to be the 23rd.
How many books does she check with and without stopping when it is found? Which statement models stopping?
Try it first, then show the solutionSolution
- With break: books 1 to 23 are checked, then the loop ends.
- Without break: all 200 are checked.
Answer: 23 with break, 200 without; break models stopping once found.
Memory hook: Found it? break.
Topics in this chapter
Flow of Control: syntax and key facts
- range()
- range(start, stop, step): start, start+step, ... while < stop (step > 0) or > stop (step < 0)
- stop is never included; step cannot be 0.
- Number of passes
- len(range(a, b)) = b - a for b > a; nested m × n
- range(1, n + 1) gives n passes.
- if-elif-else
- Only the first True branch runs
- Order the conditions from most to least specific.
- break / continue
- break: leave the innermost loop; continue: skip to the next pass
- Neither affects an outer loop.
- Accumulators
- sum starts at 0; product (factorial) starts at 1; count starts at 0
- Initialise before the loop, not inside it.
- Digit loop
- digit = n % 10; n = n // 10 while n > 0
- Gives digits from the right: reverse, sum, count, palindrome.
Flow of Control: diagrams to practise
Practise each one on paper: draw it from the checklist, then tick off every label.
Flowchart of a while loop (sum of first n numbers)
Draw a flowchart for a program with a loop.
Draw
- Start oval; input n (parallelogram); set i = 1, s = 0 (rectangle).
- Diamond 'i <= n?'.
- True exit: rectangle 's = s + i, i = i + 1' with an arrow back to the diamond.
- False exit: print s (parallelogram), then End oval.
Label
- Start
- Input n
- i = 1, s = 0
- i <= n?
- True / False
- s = s + i; i = i + 1
- Print s
- End
Watch out: The arrow back to the decision is what shows repetition; draw it clearly.
How the school exam asks Flow of Control
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Predict the output | A loop with range(), break/continue or a nested loop; give the exact output (2-3 marks). | Trace in a table; mark where break or continue fires; check end= and sep=. |
| Count iterations / convert loops | "How many times will the loop run?" "Rewrite using while instead of for" (2 marks). | Write the values range() gives; for while, add an initialisation, a condition and an update. |
| Find and correct errors | Fix missing colons, wrong indentation, = instead of ==, an infinite loop (2 marks). | Check every if/for/while line for a colon and the block for consistent indentation. |
| Write a program | Absolute value, largest/sorted of three, leap year, grade, factorial, series sum, pattern, prime, digit sum (3-5 marks). | Input with conversion, the right loop or decision, an accumulator initialised before the loop, a labelled output. |
| Flowchart of a loop | Draw the flowchart for a program with a loop or if-elif (3 marks). | Diamond for the condition, an arrow back to it for the loop, labelled True/False exits. |
Tricks to remember Flow of Control
Short memory aids. Say each one aloud once, then use it on a question the same day.
Colon then indent
Every if, elif, else, for and while line ends with a colon and is followed by an indented block.
Use it when: Spotting syntax errors.
range stops short
range(1, 10) is like a lift that stops one floor before 10.
Use it when: Counting values and last values of range().
break breaks out, continue carries on
break leaves the loop; continue jumps to the next round.
Use it when: Output questions with both.
Outer = rows, inner = columns
In patterns the outer loop prints lines and the inner loop fills each line.
Use it when: Writing pattern programs.
Sum 0, product 1
Start a sum at 0 and a product (factorial) at 1.
Use it when: Accumulators in series and factorial programs.
Flow of Control: exam-level solved questions
Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Divisibility test · 2 marks · Short answerExam level
Write a program to check whether 924 is divisible by both 4 and 7, by only one of them, or by neither.
Try it first, then show the solutionSolution
n = 924 if n % 4 == 0 and n % 7 == 0: print('Both') elif n % 4 == 0 or n % 7 == 0: print('Only one') else: print('Neither')- 924 = 4 × 231 = 7 × 132, so both tests pass.
Answer: Both
Example 2: Loop count with a negative step · 2 marks · Short answerHarder exam level
How many times does each loop run, and what is printed last?
(a) for i in range(20, 2, -4): print(i)
(b) for i in range(-5, 5, 3): print(i)
Try it first, then show the solutionSolution
- (a) 20, 16, 12, 8, 4: 5 passes; last printed 4.
- (b) -5, -2, 1, 4: 4 passes; last printed 4.
Answer: (a) 5 times, last 4 (b) 4 times, last 4.
Example 3: break inside nested loops · 3 marks · Short answerHOTS / competency
Give the output:
for i in range(1, 4):
for j in range(1, 4):
if j == i:
break
print(i, j)Try it first, then show the solutionSolution
- i = 1: j = 1 equals i, break at once; nothing printed.
- i = 2: j = 1 printed as '2 1'; j = 2 breaks.
- i = 3: '3 1', '3 2' printed; j = 3 breaks. The outer loop is never broken.
Answer: 2 1
3 1
3 2
Example 4: while with continue · 3 marks · Short answerHarder exam level
Give the output:
i = 0
total = 0
while i < 10:
i += 1
if i % 4 == 0:
continue
total += i
print(i, total)Try it first, then show the solutionSolution
- i runs 1 to 10; i is updated before continue, so the loop ends normally.
- Skipped: 4 and 8. total = 55 - 12 = 43.
- After the loop i = 10.
Answer: 10 43
Example 5: Prime check with break · 3 marks · Short answerHarder exam level
Write a program to print all prime numbers between 20 and 40 using a nested loop and break.
Try it first, then show the solutionSolution
for n in range(20, 41): prime = True for d in range(2, n): if n % d == 0: prime = False break if prime: print(n, end=' ')- break stops checking as soon as one divisor is found.
Answer: 23 29 31 37
Example 6: Alternating series · 3 marks · Short answerHOTS / competency
Write a program to find S = 1 - 2 + 3 - 4 + ... ± n for n = 9 and n = 10, and state a rule that gives S without a loop.
Try it first, then show the solutionSolution
for n in (9, 10): s = 0 for i in range(1, n + 1): if i % 2 == 1: s += i else: s -= i print(n, s)- Pairs (1 - 2), (3 - 4), ... each give -1. For even n, S = -n/2; for odd n, S = (n + 1)/2.
Answer: 9 5
10 -5
Example 7: Number pyramid · 3 marks · Short answerHOTS / competency
Write a program to print this pattern:
1
121
12321
1234321
Try it first, then show the solutionSolution
- Row i (1 to 4): 4 - i spaces, then 1 to i, then i - 1 down to 1.
n = 4 for i in range(1, n + 1): print(' ' * (n - i), end='') for j in range(1, i + 1): print(j, end='') for j in range(i - 1, 0, -1): print(j, end='') print()
Answer: 1
121
12321
1234321
Example 8: Rewrite for as while · 2 marks · Short answerExam level
Rewrite using a while loop and give the output:
for k in range(5, 26, 5):
print(k, end=' ')
Try it first, then show the solutionSolution
k = 5 while k < 26: print(k, end=' ') k += 5- Values 5, 10, 15, 20, 25.
Answer: 5 10 15 20 25
Case-study practice (Section E style)
Read the situation, then answer every part. In a school exam set on the board pattern this is a 4-mark question split into 1 + 2 + 1 marks.
Exam-hall seat allotment
Suppose an exam hall has 5 rows of 6 seats. The invigilator numbers seats row by row from 1 to 30, and wants to leave every seat whose number is a multiple of 4 empty for spacing. A student script prints the seat plan using nested loops: an 'X' for an empty seat and the seat number otherwise.
(i) · 1 mark
How many times does the inner loop body run in total?
Answer
Answer: 5 × 6 = 30 times.
Each of the 5 outer passes runs all 6 inner passes.
(ii) · 2 marks
Write the program.
Answer
Answer:
Output row 1: ' 1 2 3 X 5 6'seat = 0 for r in range(5): for c in range(6): seat += 1 if seat % 4 == 0: print(' X', end=' ') else: print(f'{seat:2}', end=' ') print()seat counts across rows; % 4 marks every fourth seat. (f'{seat:2}' pads to width 2; print(seat, end=' ') is also acceptable.)
(iii) · 1 mark
How many students can be seated, and which statement would you add to stop filling the plan once 20 students are seated?
Answer
Answer: 30 - 7 = 23 seats are usable (multiples of 4 up to 30: 4, 8, ..., 28 are 7 seats). To stop at 20 students, count seated students and use break in the inner loop plus a check in the outer loop, since break leaves only the inner loop.
break affects only the innermost loop, so a flag or second check is needed for the outer loop.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
Write a program to input a number and print its absolute value without using abs(). [2 marks] (2 marks)
| Step | Marks |
|---|---|
| n = int(input(...)) or float(input(...)) | 0.5 |
| if n < 0: n = -n | 1 |
| print(n) with a label | 0.5 |
Write a program to input a positive integer and print its factorial using a while loop. [3 marks] (3 marks)
| Step | Marks |
|---|---|
| Input n and initialise fact = 1 and the counter | 1 |
| while loop with the correct condition multiplying fact and updating the counter | 1.5 |
| Printing the result after the loop | 0.5 |
Write a program to input n and x and print the sum of the series 1 + x + x²/2 + x³/3 + ... + xⁿ/n. Also print how many terms are greater than 1. [5 marks] (5 marks)
| Step | Marks |
|---|---|
| Input n and x with conversion | 0.5 |
| Initialise s = 1 (first term) and count = 0 | 1 |
| for i in range(1, n + 1) with term = x ** i / i | 1.5 |
| s += term and if term > 1: count += 1 | 1 |
| Print s and count after the loop | 1 |
Where students lose marks in Flow of Control
The slips examiners see most often, and what to write instead.
Mistake: Including stop in range()
range never produces the stop value.
Wrong working
for i in range(1, 5): prints 1 2 3 4 5
Right working
for i in range(1, 5): prints 1 2 3 4
Do this: Use range(1, n + 1) when n must be included.
Usually costs: 1 mark
Mistake: Using separate ifs where elif is needed
Separate ifs are all tested, so more than one block can run.
Wrong working
if m >= 80: print('A')
if m >= 60: print('B') # m = 85 prints A and BRight working
if m >= 80: print('A')
elif m >= 60: print('B') # prints only ADo this: Use elif for mutually exclusive choices.
Usually costs: 1 mark
Mistake: Initialising the accumulator inside the loop
It is reset on every pass, so only the last value survives.
Wrong working
for i in range(1, 6):
s = 0
s = s + iRight working
s = 0
for i in range(1, 6):
s = s + iDo this: Initialise totals, products and counters before the loop.
Usually costs: 1 mark
Mistake: Forgetting to update the while variable
The condition never becomes False: infinite loop.
Wrong working
i = 1
while i <= 5:
print(i)Right working
i = 1
while i <= 5:
print(i)
i += 1Do this: Every while loop needs an initialisation, a condition and an update.
Usually costs: 1 mark
Mistake: Thinking break exits all nested loops
break leaves only the innermost loop in which it appears.
Wrong working
Saying the outer loop also stops
Right working
The outer loop goes on to its next pass
Do this: Trace the outer loop separately after a break.
Usually costs: 1 mark
NCERT exercise guide: Flow of Control
What each exercise in the NCERT chapter tests, how to approach it, and a question of the same kind solved step by step. Questions here are written in our own words.
NCERT Chapter 6 exercise: programs with conditions and loops
What it tests: Programs on decisions (largest, grade, leap year), loops (multiples, factors, series, factorial), patterns, and output-finding questions.
How to approach it: Decide first: decision only, fixed-count loop (for) or condition loop (while). Initialise accumulators outside the loop; trace your program for two inputs before writing the answer.
Same kind as the 'print the factors of a number' program
Write a program to print all factors of 36 and how many there are.
Show the solutionSolution
n = 36 count = 0 for d in range(1, n + 1): if n % d == 0: print(d, end=' ') count += 1 print() print('Factors:', count)
Answer: 1 2 3 4 6 9 12 18 36
Factors: 9
NCERT Chapter 6 exercise: patterns
What it tests: Printing number and star patterns with nested loops.
How to approach it: Write how many items are on row i; let the inner range depend on i.
Same kind as the pattern-printing questions
Print an inverted star triangle of 4 rows (4 stars, then 3, 2, 1).
Show the solutionSolution
- Row i from 4 down to 1 prints i stars.
for i in range(4, 0, -1): print('*' * i)
Answer: ****
***
**
*
Practice questions on Flow of Control
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQExam level
What will range(10, 1, -3) produce? (a) 10 7 4 1 (b) 10 7 4 (c) 7 4 1 (d) 10 7 4 1 -2
Hint
Stop value 1 is excluded.
Answer
(b) 10 7 4
Q2 · 1 mark · Very short answerHarder exam level
How many times is 'Hi' printed?
for i in range(3):
for j in range(i):
print('Hi')Hint
Inner passes: 0, 1, 2.
Answer
3 times.
Q3 · 3 marks · Short answerExam level
Write a program to input a year and print whether it is a leap year.
Hint
Divisible by 400, or by 4 but not by 100.
Answer
y = int(input('Year: '))
if y % 400 == 0 or (y % 4 == 0 and y % 100 != 0):
print('Leap year')
else:
print('Not a leap year')Q4 · 2 marks · Short answerHarder exam level
Predict the output:
x = 1 while x < 100: x = x * 3 if x % 2 == 0: break print(x)Hint
Powers of 3 are odd.
Answer
243 (3, 9, 27, 81, 243; no even value, so the loop ends when x ≥ 100).
Q5 · 2 marks · Short answerExam level
Find the errors and rewrite:
for i in range(1, 6)
if i % 2 = 0
print(i)Hint
Colons, ==, indentation.
Answer
for i in range(1, 6):
if i % 2 == 0:
print(i)Q6 · 2 marks · Short answerHarder exam level
Predict the output:
for i in 'CODE': if i in 'AEIOU': continue print(i.lower(), end='')Hint
Vowels are skipped.
Answer
cd
Q7 · 3 marks · Short answerHarder exam level
Write a program to print the sum of the digits of 90517 and the number of odd digits in it.
Hint
Use n % 10 and n // 10.
Answer
n = 90517
s = c = 0
while n > 0:
d = n % 10
s += d
if d % 2 == 1:
c += 1
n //= 10
print(s, c)
Output: 22 4Q8 · 1 mark · MCQHarder exam level
Assertion (A): The statement in a while loop's block may never execute. Reason (R): The condition of a while loop is checked before each pass. Choose (a) both true, R explains A (b) both true, R does not explain A (c) A true, R false (d) A false, R true.
Hint
What if the condition is False at the start?
Answer
(a)
Q9 · 3 marks · Short answerHOTS / competency
Write a program to print the first 10 terms of the Fibonacci series 0, 1, 1, 2, 3, ... and the sum of its even terms.
Hint
Even terms among 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
Answer
a, b = 0, 1
s = 0
for i in range(10):
print(a, end=' ')
if a % 2 == 0:
s += a
a, b = b, a + b
print()
print(s)
Output: 0 1 1 2 3 5 8 13 21 34, then 44Q10 · 2 marks · Short answerHOTS / competency
Why does this loop never end, and how would you fix it?
i = 10
while i != 0:
i -= 3Hint
Values: 10, 7, 4, 1, -2 ...
Answer
i goes 10, 7, 4, 1, -2, -5 ... and never equals 0, so the condition i != 0 stays True for ever. Use while i > 0 instead.
Q11 · 3 marks · Short answerHOTS / competency
Write a program that keeps reading marks until -1 is entered and then prints the highest mark entered (assume at least one mark).
Hint
Sentinel-controlled while loop.
Answer
m = int(input())
high = m
while m != -1:
if m > high:
high = m
m = int(input())
print('Highest:', high)Q12 · 1 mark · Very short answerExam level
Write the output of print(sum(range(1, 101, 2))).
Hint
Sum of the first 50 odd numbers.
Answer
2500
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does range(4) produce?Show answer
0, 1, 2, 3.
2.What is the default step of range()?Show answer
1.
3.Which loop is used when the number of repetitions is not known in advance?Show answer
The while loop.
4.What does continue do?Show answer
Skips the rest of the current pass and moves to the next pass.
5.What error does inconsistent indentation give?Show answer
IndentationError (a syntax error).
6.How many times does the inner block run in two nested loops of 3 and 4 passes?Show answer
12.
7.What is 0! ?Show answer
1.
Best order to study it
- Sequential flow, blocks and indentation.
- if, if-else, if-elif-else; absolute value, sorting three numbers, divisibility.
- for loops and range() with all three forms.
- while loops; digit-based programs.
- break and continue; tracing.
- Nested loops and patterns.
- Series, factorial, prime and other accumulator programs.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- Blocks are marked by indentation after a line ending with a colon.
- if-elif-else runs only the first True branch.
- for item in sequence; range(start, stop, step), stop excluded.
- while repeats while the condition is True; update the variable to avoid an infinite loop.
- break leaves the innermost loop; continue skips to the next pass.
- Nested loops: inner runs fully for each outer pass; outer = rows, inner = columns.
- Sum starts at 0, factorial at 1; n % d == 0 tests divisibility.
Flow of Control: frequently asked questions
Is the else clause on loops in the syllabus?
The 2026-27 syllabus names if, if-else, if-elif-else, for, range(), while, break, continue and nested loops. The loop-else clause is not listed, so it is not needed for this chapter.
When should I use for and when while?
Use for when you know how many times to repeat or are going through a sequence (range, string, list). Use while when you repeat until a condition changes, such as reading input until 0 or processing digits until the number becomes 0.
Can range() take float values?
No. range() needs integers; range(0, 1, 0.1) gives a TypeError. Use a counter and divide, e.g. i / 10, if you need decimal steps.
What does pass do in a block?
pass is a statement that does nothing; it fills a block that must not be empty, such as an if you will write later. It is a keyword, but the syllabus does not ask about it specifically.
Why does my pattern print everything on one line?
Inside the inner loop you used end=' ' to stay on the row, but forgot the empty print() after the inner loop that moves to the next line.
Based on: CBSE Computer Science (083) syllabus, Class XI 2026-27; NCERT Computer Science, Textbook for Class XI, Chapter 6 Flow of Control (Reprint 2026-27)