Computational Thinking and Programming-I Quiz 9

πŸ” Computational Thinking & Programming-I Quiz 9 β€” Loops & Iteration (Class 11 CS)

Practice 20 CBSE Class 11 Computer Science (Code 083) MCQs on iterative statements β€” for loops, range(), while loops, break & continue, nested loops, and classic beginner programs like pattern generation, summation of a series, and factorial.

Every code example below has been verified by actually running it in Python β€” including fixes to two questions from the original quiz that had duplicate or contradictory options. Tap any question to reveal the answer with a clear explanation.

πŸ” For LoopπŸ”’ range()πŸ”‚ While LoopπŸ›‘ Loop ControlπŸͺ† Nested Loops⭐ Suggested Programs
Q1
πŸ” For Loop

Which iterative statement is used to execute a block of code a specific, known number of times?

  1. for loop
  2. while loop
  3. if statement
  4. switch statement
Show Answer & Explanation

βœ… Answer: (a) for loop

A for loop is the natural choice when you already know how many times to repeat something β€” e.g. iterating a fixed number of times using range(), or once per item in a list.

Q2
πŸ”’ range()

What is the purpose of the range() function in Python?

  1. To generate a sequence of numbers
  2. To perform mathematical calculations
  3. To create a list of values directly
  4. To define the limits of a loop only visually
Show Answer & Explanation

βœ… Answer: (a) To generate a sequence of numbers

range() generates a sequence of numbers β€” commonly used to control how many times a for loop runs, or to produce a specific numeric pattern.

Q3
πŸ” For Loop

Which of the following correctly shows the different valid forms of range() usable in a for loop’s syntax?

  1. for i in range(stop):
  2. for i in range(start, stop):
  3. for i in range(start, stop, step):
  4. All of the above are valid forms
Show Answer & Explanation

βœ… Answer: (d) All of the above are valid forms

range() is flexible β€” it accepts 1, 2, or 3 arguments: just a stop value, a start and stop, or a start, stop, and step. All three forms shown are valid Python syntax. (This question is corrected from the original, whose four options included two identical duplicates of the same 3-argument form β€” leaving no way to answer correctly as originally written.)

Q4
πŸ”‚ While Loop

What is the purpose of the while loop?

  1. To execute a block of code a fixed, predetermined number of times
  2. To execute a block of code repeatedly as long as a condition remains true
  3. To terminate the program immediately
  4. To define the limits of a for loop
Show Answer & Explanation

βœ… Answer: (b) To execute a block of code repeatedly as long as a condition remains true

A while loop keeps repeating its block as long as its condition stays true β€” ideal when you don’t know in advance exactly how many repetitions will be needed.

Q5
πŸ›‘ Loop Control

Which statement is used to terminate a loop prematurely, stopping it entirely before all iterations complete?

  1. return statement
  2. exit statement
  3. break statement
  4. continue statement
Show Answer & Explanation

βœ… Answer: (c) break statement

break exits the loop immediately and completely β€” no further iterations run at all, and execution jumps to the code right after the loop.

Q6
πŸ›‘ Loop Control

Which statement is used to skip the rest of the current iteration and move on to the next one, without exiting the loop?

  1. return statement
  2. exit statement
  3. break statement
  4. continue statement
Show Answer & Explanation

βœ… Answer: (d) continue statement

continue stops the current pass through the loop body right where it is, and jumps to the next iteration β€” unlike break, the loop itself keeps running.

Q7
πŸͺ† Nested Loops

What is a nested loop?

  1. A loop that executes infinitely
  2. A loop placed inside another loop
  3. A loop that terminates prematurely
  4. A loop that skips certain iterations
Show Answer & Explanation

βœ… Answer: (b) A loop placed inside another loop

A nested loop is simply a loop written inside the body of another loop β€” commonly used for tasks like generating 2D patterns or grids, where the outer loop controls rows and the inner loop controls columns.

Q8
⭐ Suggested Programs

Which of the following is a classic suggested program that relies on nested for loops?

  1. A program to check if a number is prime
  2. A program to calculate the square root of a number
  3. A program to generate a star or number pattern (like a triangle)
  4. A program to find the absolute value of a number
Show Answer & Explanation

βœ… Answer: (c) A program to generate a star or number pattern (like a triangle)

Pattern-generation programs (printing triangles, pyramids of stars or numbers) are the textbook example of nested for loops β€” the outer loop handles each row, and the inner loop prints the characters within that row.

Q9
⭐ Suggested Programs

What does a program that calculates the summation of a series of numbers using a for loop ultimately produce?

  1. The product of the series
  2. The average of the series
  3. The sum of the series
  4. The difference between consecutive terms
Show Answer & Explanation

βœ… Answer: (c) The sum of the series

A summation program accumulates a running total inside the loop (e.g. total += i) and ends up with the sum of the series β€” as opposed to a product (which would need multiplication) or an average (which needs an extra division step).

Q10
πŸ›‘ Loop Control

What is the key difference between break and continue in a loop?

  1. break exits the entire loop immediately; continue skips only the current iteration and moves to the next
  2. break skips only the current iteration; continue exits the entire loop
  3. They behave in exactly the same way
  4. Both statements immediately terminate the whole program
Show Answer & Explanation

βœ… Answer: (a) break exits the entire loop immediately; continue skips only the current iteration and moves to the next

break stops the loop completely β€” no more iterations happen at all. continue just skips whatever’s left in the current iteration and lets the loop carry on to the next one. (This question replaces a self-contradictory one from the original quiz, whose wording β€” β€œexit a loop prematurely and move to the next iteration” β€” actually describes break and continue’s behaviours mixed together, which doesn’t match either statement individually.)

Q11
πŸ”’ range()

What does range(2, 10, 2) generate in Python?

  1. [2, 4, 6, 8, 10]
  2. [2, 4, 6, 8]
  3. [2, 3, 4, …, 9]
  4. [0, 2, 4, 6, 8]
Show Answer & Explanation

βœ… Answer: (b) [2, 4, 6, 8]

Starting at 2, stepping by 2, and stopping before 10 (exclusive), range(2, 10, 2) produces [2, 4, 6, 8].

Q12
πŸ” For Loop

What does the following program print?

total = 0
for i in range(1, 6):
    total += i
print(total)
  1. 10
  2. 15
  3. 21
  4. 6
Show Answer & Explanation

βœ… Answer: (b) 15

This adds up 1 + 2 + 3 + 4 + 5 = 15. range(1, 6) produces 1 through 5 (6 is excluded).

Q13
πŸ”‚ While Loop

What does the following program print? (It calculates a factorial.)

n = 5
fact = 1
i = 1
while i <= n:
    fact *= i
    i += 1
print(fact)
  1. 25
  2. 120
  3. 15
  4. 20
Show Answer & Explanation

βœ… Answer: (b) 120

This multiplies 1 Γ— 2 Γ— 3 Γ— 4 Γ— 5 = 120 β€” the factorial of 5, computed using a while loop that stops once i passes n.

Q14
πŸͺ† Nested Loops

What does the following nested loop print, row by row?

for i in range(3):
    row = ""
    for j in range(i + 1):
        row += "*"
    print(row)
  1. *, *, *
  2. *, **, ***
  3. ***, **, *
  4. * * *
Show Answer & Explanation

βœ… Answer: (b) *, **, ***

The outer loop runs for i = 0, 1, 2. On each pass, the inner loop adds (i+1) stars, building a growing triangle: *, then **, then *** β€” a classic nested-loop pattern program.

Q15
πŸ›‘ Loop Control

What does the following program print?

i = 0
while True:
    if i == 3:
        break
    print(i)
    i += 1
  1. 0, 1, 2, 3
  2. 0, 1, 2
  3. 1, 2, 3
  4. An infinite loop that never stops
Show Answer & Explanation

βœ… Answer: (b) 0, 1, 2

while True would normally loop forever, but the break stops it the moment i reaches 3 β€” so only 0, 1, 2 get printed before the loop exits.

Q16
πŸ›‘ Loop Control

What does the following program print?

for i in range(5):
    if i % 2 == 0:
        continue
    print(i)
  1. 0, 2, 4
  2. 1, 3
  3. 0, 1, 2, 3, 4
  4. 1, 3, 5
Show Answer & Explanation

βœ… Answer: (b) 1, 3

For every even i (0, 2, 4), continue skips the print() line entirely. Only the odd values actually get printed: 1, 3.

Q17
πŸ”’ range()

What does range(5, 1, -1) generate in Python?

  1. [5, 4, 3, 2, 1]
  2. [5, 4, 3, 2]
  3. [1, 2, 3, 4, 5]
  4. Error, since step can’t be negative
Show Answer & Explanation

βœ… Answer: (b) [5, 4, 3, 2]

With a negative step, range() counts downward: starting at 5, decreasing by 1 each time, and stopping before it reaches 1 (exclusive): [5, 4, 3, 2].

Q18
πŸͺ† Nested Loops

How many total times does the inner loop’s body run in the following code?

for i in range(3):
    for j in range(4):
        pass
  1. 3
  2. 4
  3. 7
  4. 12
Show Answer & Explanation

βœ… Answer: (d) 12

The outer loop runs 3 times, and for each of those, the inner loop runs 4 times β€” so the inner body executes 3 Γ— 4 = 12 times in total.

Q19
πŸ”‚ While Loop

What is the risk of writing while True: without ever including a break or a condition change inside the loop?

  1. Python automatically stops it after 1000 iterations
  2. It creates an infinite loop that never stops on its own
  3. It raises a SyntaxError immediately
  4. Nothing β€” Python optimizes it away
Show Answer & Explanation

βœ… Answer: (b) It creates an infinite loop that never stops on its own

Since the condition True is always true, the loop has no natural way to stop β€” without a break (or something that eventually makes the condition false), it becomes an infinite loop, and the program will hang until manually interrupted.

Q20
⭐ Suggested Programs

Which control structure is best suited for generating star or number patterns like triangles and pyramids?

  1. A single if statement
  2. A single while loop with no nesting
  3. Nested for loops (an outer loop for rows, an inner loop for columns)
  4. The break statement alone
Show Answer & Explanation

βœ… Answer: (c) Nested for loops (an outer loop for rows, an inner loop for columns)

Nested for loops are the standard tool for pattern generation β€” the outer loop controls how many rows to print, and the inner loop controls how many characters go in each row.

Jitendra Singh
βœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me β†’