📌 Snapshot
- Flow of control is the order in which statements in a Python program are executed; it can be sequential, selective, or repetitive.
- Selection (
if,if..else,if..elif..else) is the mechanism for decision-making in Python, replacing the default top-to-bottom sequence when a condition must be evaluated. - Indentation is a first-class syntactic rule in Python (unlike curly-bracket languages), making it directly testable in CUET.
- Repetition through
forandwhileloops — including therange()function,break,continue, and nested loops — is the most MCQ-heavy portion of this topic. - CUET tests this area heavily for output-tracing, syntax identification, and choosing the correct loop/control construct for a described scenario.
📖 Detailed Notes
2.1 Core concepts
- Flow of control is defined as the order of execution of statements in a program. It can be implemented using control structures. Python supports two types of control structures: selection and repetition. The default execution order (statement by statement from top to bottom) is called sequence. (NCERT §6.1, p. 121)
- Selection (
if..else) is used when a decision must be made between two or more alternative paths. The concept of selection is implemented using theif..elsestatement in Python. (NCERT §6.2, p. 122) - The syntax of the simple
ifstatement is:if condition:followed by an indented block ofstatement(s). If the condition is true, the indented statements execute; if false, they are skipped. (NCERT §6.2, p. 123) - The
if..elsestatement allows two alternative blocks: theifblock executes when the condition is true, and theelseblock executes when the condition is false. (NCERT §6.2, p. 123) - The
if..elif..elsechain (whereelifmeanselse..if) is used when multiple conditions must be checked in sequence. As soon as one condition is true, its indented block executes and the rest of theifstatement terminates. The number ofelifclauses depends on the number of conditions. (NCERT §6.2, p. 124) - A nested
ifis anif..elseplaced inside anotheriforelifblock. Python allows many levels of such nesting. (NCERT §6.2, p. 126) - Indentation in Python refers to the leading whitespace (spaces or tabs) at the beginning of a statement. The same level of indentation associates statements into a single block of code. Python's interpreter checks indentation strictly and raises a syntax error if it is incorrect. The common practice is to use a single tab for each level. Unlike most other languages, Python does not use curly brackets for blocks. (NCERT §6.3, p. 126)
- Repetition (also called iteration) means executing a set of statements repeatedly. This is implemented using looping constructs. Python provides two looping constructs:
forandwhile. The condition is checked based on the value of a control variable. When the condition becomes false, the loop terminates. The programmer must ensure an exit condition exists; otherwise an infinite loop results. (NCERT §6.4, p. 127–128) - The
forloop iterates over a range of values or a sequence (numeric values, characters of a string, elements of a list or tuple). It is used when the number of iterations is known in advance. Syntax:for <control-variable> in <sequence/range>:followed by the indented body. When all items in the range are exhausted, control transfers to the statement after the loop. (NCERT §6.4.1, p. 128) - The
range()function is a built-in Python function with syntaxrange([start], stop[, step]). It generates a sequence of integers fromstartup to (but not including)stop, incrementing bystep. Defaultstartis 0; defaultstepis 1.stepcan be a positive or negative integer but not zero. All parameters must be integers. (NCERT §6.4.1(B), p. 130) - The
whileloop executes its body repeatedly as long as the control condition is true. The condition is evaluated before each iteration. If the condition is initially false, the body is not executed even once. The body must contain statements that eventually make the condition false to avoid an infinite loop. (NCERT §6.4.2, p. 131) - The
breakstatement immediately exits (terminates) the current loop and resumes execution at the statement following the loop body. It alters the normal flow of execution inside a loop. (NCERT §6.5.1, p. 133) - The
continuestatement skips the remaining statements of the current iteration and jumps back to the beginning of the loop for the next iteration. Unlikebreak,continuedoes not exit the loop — it only skips the rest of the current pass. (NCERT §6.5.2, p. 135) - Nested loops: A loop contained within another loop is called a nested loop. Python imposes no restriction on how many loops can be nested or on levels of nesting. Any combination of
forandwhileloops can be nested. For each single iteration of the outer loop, the inner loop runs through its complete cycle. (NCERT §6.6, p. 136–137)
2.2 Definitions to memorise
| Term | Definition | Page |
|---|---|---|
| Flow of control | The order of execution of statements in a program | 121 |
| Sequence | Default execution order — one statement after another from beginning to end | 121 |
| Selection | A control structure that chooses between two or more alternative paths based on a condition; implemented using if..else |
122 |
| Indentation | Leading whitespace (spaces/tabs) at the beginning of a statement; used by Python to define blocks of code | 126 |
| Repetition / Iteration | Executing a set of statements repeatedly using a loop construct | 127 |
| Control variable | The variable whose value is checked to determine whether a loop continues or terminates | 128 |
| Infinite loop | A loop that never terminates because the condition never becomes false; a logical error | 128 |
for loop |
A looping construct that iterates over each item in a range or sequence; number of iterations is known in advance | 128 |
range() |
A built-in Python function that generates a sequence of integers; syntax: range([start], stop[, step]) |
130 |
while loop |
A looping construct that executes its body as long as the test condition remains true; number of iterations need not be known in advance | 131 |
break statement |
Immediately exits the current loop; execution resumes after the loop body | 133 |
continue statement |
Skips the remaining statements of the current iteration and jumps to the next iteration of the loop | 135 |
| Nested loop | A loop contained inside another loop | 136 |
if statement |
Simple selection construct that executes a block when its condition is True | 123 |
if..else statement |
Two-way selection executing one block on True and another on False | 123 |
if..elif..else statement |
Multi-way selection that checks several conditions in sequence | 124 |
Nested if |
An if..else placed inside another if or elif block |
126 |
| Block | A group of statements sharing the same indentation level | 126 |
elif |
Python keyword meaning "else if"; used in multi-way selection | 124 |
pass statement |
Null statement used as a placeholder where syntactically a statement is required | 122 |
Step parameter (range) |
Increment between successive values in a range(); may be positive or negative but not zero |
130 |
Stop value (range) |
Exclusive upper limit of range(); the generated sequence stops before this value |
130 |
Start value (range) |
Inclusive lower limit of range(); default is 0 if omitted |
130 |
| Counter-controlled loop | Loop driven by a counter variable typical of for constructs |
128 |
| Condition-controlled loop | Loop whose iteration depends on a Boolean test typical of while |
131 |
2.3 Diagrams / processes to remember
- Figure 6.2 (p. 122): Flowchart depicting decision making — shows a diamond (decision) shape with
num1 > num2?; the "Yes" branch computesdiff = num1 - num2, the "No" branch computesdiff = num2 - num1. Illustrates theif..elsestructure visually. - Figure 6.4 (p. 128): Flowchart of the
forloop — Start → Initialisation → Test Expression → (True) Body of For Loop → back to Test Expression; (False) → Exit for Loop → Statement following the loop → Stop. - Figure 6.5 (p. 131): Flowchart of the
whileloop — Start → Initialisation → Test Expression → (True) Body of while Loop → back to Test Expression; (False) → Statements following while loop → Stop. - Figure 6.5 / break flowchart (p. 133): Flowchart showing
break— within the loop body, if the break condition is encountered, control immediately exits the loop to the statement following it. - Figure 6.6 (p. 135): Flowchart of
continue— whencontinueis encountered, control jumps back to the loop condition check (not to the statement after the loop), skipping remaining statements of that iteration.
2.4 Common confusions / NTA trap points
breakvscontinue: Students confuse the two.breakexits the loop entirely;continueonly skips the rest of the current iteration and re-checks the loop condition. NTA frequently presents code snippets and asks what is printed — identifying whetherbreakorcontinueis present is critical.range()stop value is exclusive:range(1, 6)produces 1, 2, 3, 4, 5 — NOT 6. NTA constructs distractors that include the stop value in the output. Also,range(10)starts at 0, not 1.whileloop with initially-false condition: If the condition is false from the start, the body executes zero times. NTA asks "how many times is the body executed?" for such cases.elifvselse:elifchecks a new condition;elsecatches all remaining cases. Usingelif conditionwithout a finalelsemeans nothing executes if all conditions are false — NTA tests this with output-tracing questions.- Indentation errors (NCERT §6.3, p. 126). A statement with wrong indentation belongs to a different block. NTA may show code where a
printis at the wrong indent level inside a loop orif, and ask for the output — the answer changes entirely based on indentation. range()step cannot be zero (NCERT §6.4.1(B), p. 130).range(0, 5, 0)raises ValueError. NTA distractor may claim step=0 produces an infinite sequence.forloops do NOT need to know iteration count at compile time (NCERT §6.4.1, p. 128). They iterate over any sequence; the programmer must know the iteration count, but Python figures it out at runtime.breakonly exits the innermost loop (NCERT §6.5.1, p. 133). In nested loops,breakdoes not exit all enclosing loops. NTA traps assumebreak"exits all loops".elseclause on loops is outside the NCERT syllabus here. Stick to NCERT —for..else/while..elseare not covered. Avoid that in CUET answers.- Negative step requires start > stop (NCERT §6.4.1(B), p. 130).
range(0, 9, -1)yields an empty sequence;range(9, 0, -1)yields 9, 8, ..., 1. - Iteration variable persists after the loop (NCERT §6.4.1). After
for i in range(5):,iis 4 outside the loop body. NTA may use this in output-tracing.
🎯 Practice MCQs
First 3 questions free · create a free account to unlock the rest — answers & explanations included, no payment needed
Q1. What will be the output of the following Python code? ```python for i in range(2, 10, 3): print(i, end=' ') ```
▸ Show answer & explanation
Answer: C
`range(2, 10, 3)` generates 2, 5, 8 — starting at 2, incrementing by 3, and stopping before 10. 11 would exceed the stop value of 10, so (A) is wrong. Options (B) and (D) use an incorrect step value. ---
Q2. Which of the following statements about indentation in Python is correct?
▸ Show answer & explanation
Answer: B
The NCERT explicitly states that Python uses indentation (not curly brackets) for blocks, the interpreter checks indentation strictly, and throws syntax errors if indentation is incorrect. (A) is wrong because Python does not use curly brackets for blocks; (C) is wrong because indentation is required for all compound statements; (D) is wrong because all statements within the same block must use the same level of indentation. ---
Q3. Consider the following code segment: ```python num = 0 for num in range(10): num = num + 1 if num == 8: break print('Num has value ' + str(num)) print('Encountered break!! Out of loop') ``` How many times is `'Num has value ...'` printed?
▸ Show answer & explanation
Answer: D
The loop runs with `num` taking values from `range(10)` (0–9). Inside, `num` is incremented by 1 before the check. When `num` becomes 8, `break` is executed before the `print` statement, so values 1 through 7 are printed — a total of 7 times. (C) 8 is the classic distractor, but the `break` fires before the print for `num == 8`. ---
🔒 12 more practice MCQs
Create a free account to unlock every MCQ in this chapter — answers and explanations included. No payment needed.
Already registered? Just log in and they'll all appear here.
Q4. Assertion (A): The body of a `while` loop may never execute even once. Reason (R): If the condition of the `while` loop is initially false, the body is not executed.
▸ Show answer & explanation
Answer: A
The NCERT explicitly states that if the while condition is initially false, the body does not execute at all. This directly explains why the body may never execute — making R the correct explanation of A. ---
Q5. Match the following Python statements with their correct descriptions: | Statement | Description | |---|---| | P. `break` | 1. Skips remaining statements of current iteration and goes to next iteration | | Q. `continue` | 2. Immediately exits the current loop | | R. `range(0, 9, -1)` | 3. Generates a decreasing sequence | | S. `elif` | 4. Means `else..if`; checks a new condition if the previous was false |
▸ Show answer & explanation
Answer: A
`break` exits the loop (P-2); `continue` skips the current iteration (Q-1); `range(0, 9, -1)` generates a decreasing sequence (R-3 — note: step -1 with start > stop generates values, though this particular call produces an empty sequence since 0 < 9; decreasing sequences need a negative step with start > stop); `elif` means `else..if` (S-4). (B) swaps P and Q, which is the most common error. ---
Q6. What is the output of the following code? ```python num = 0 for num in range(6): num = num + 1 if num == 3: continue print('Num has value ' + str(num)) print('End of loop') ```
▸ Show answer & explanation
Answer: B
`continue` skips only the current iteration when `num == 3`, so 3 is not printed. The loop resumes for subsequent iterations (4, 5, 6 are printed). "End of loop" prints after the loop finishes. (D) is wrong because `range(6)` goes 0–5, and after incrementing, values 1–6 are processed; (A) is wrong because 3 is skipped. ---
Q7. How many values does `range(5)` generate, and what is the first value?
▸ Show answer & explanation
Answer: B
`range(n)` defaults `start=0`, so it yields 0, 1, 2, 3, 4 — five values starting at 0. ---
Q8. What is the output of the following code? ```python i = 1 while i <= 5: if i == 3: i = i + 1 continue print(i, end=' ') i = i + 1 ```
▸ Show answer & explanation
Answer: B
When `i == 3`, `continue` skips the print but `i` is incremented before continue — avoiding the infinite-loop trap. The output is 1 2 4 5. ---
Q9. The output of `list(range(10, 2, -2))` is:
▸ Show answer & explanation
Answer: B
Start=10, stop=2 (exclusive), step=-2 → 10, 8, 6, 4. Stops before reaching 2. ---
Q10. Which control structure type does Python NOT support natively (as per §6.1)?
▸ Show answer & explanation
Answer: D
Python supports sequence (default), selection (`if..else`) and repetition (`for`, `while`). It does not provide a `goto` statement. ---
Q11. Output of the nested loop: ```python for i in range(3): for j in range(2): print(i, j, end=' | ') ```
▸ Show answer & explanation
Answer: A
For each i (0,1,2), j cycles through (0,1) completely before i increments. Order: (0,0)(0,1)(1,0)(1,1)(2,0)(2,1). ---
Q12. What happens if a `while` loop's condition never becomes false?
▸ Show answer & explanation
Answer: B
If no exit condition is reached the loop runs indefinitely — an infinite loop. Python does not auto-terminate it. ---
Q13. The `pass` statement is used when:
▸ Show answer & explanation
Answer: A
`pass` is a null placeholder, used where syntax demands a statement but no action is intended. ---
Q14. Assertion (A): `break` only terminates the innermost loop in which it appears. Reason (R): Python does not provide a labelled break to exit multiple nested loops simultaneously.
▸ Show answer & explanation
Answer: A
`break` exits only the innermost loop; the absence of a labelled break in Python is the reason it cannot exit multiple loops at once. ---
Q15. Output of the snippet: ```python x = 10 if x > 5: if x > 7: print("A") else: print("B") else: print("C") ```
▸ Show answer & explanation
Answer: A
10 > 5 is True → enter outer if; 10 > 7 is True → print "A".
📊 Previous-Year Questions
Practise with real CUET Computer Science previous-year papers — every question solved, with the correct answer and a step-by-step explanation.
View solved CUET PYQ papers →Ready to drill Computer Science?
Unlock all MCQs, chapter tests, mocks & PYQs for ₹199/year.
Get UniDrill Pro