Kundali IQ

Home › Free notes › Class 11 Computer Science › Flow of Control

Flow of Control – Class 11 Computer Science notes, important questions and MCQs

NCERT Class 11 Computer Science, chapter 6. Notes, key terms, important questions with answers and MCQs.

हिंदी में पढ़ें

Chapter overview

Flow of control is the order in which statements in a program are executed. Python supports sequential flow, selection using if, if-else and if-elif-else statements, and repetition using for and while loops. Indentation defines blocks of code in Python. Statements such as break and continue change the flow inside loops, and loops can be nested.

Selection

  • The if statement executes a block only when its condition is True; if-else chooses between two blocks; if-elif-else chooses among many.
  • Python uses indentation (usually 4 spaces) to mark a block; a colon ends the if, elif, else, for and while header lines.
  • Conditions use relational and logical operators, for example if marks >= 33 and attendance >= 75.

Repetition

  • The for loop iterates over a sequence; range(start, stop, step) generates numbers from start up to stop − 1, for example range(1, 6) gives 1, 2, 3, 4, 5 and range(10, 0, -2) gives 10, 8, 6, 4, 2.
  • The while loop repeats as long as its condition is True; the condition must eventually become False to avoid an infinite loop.
  • break exits the loop immediately; continue skips the rest of the current iteration; loops can be nested, as in printing patterns, where the inner loop completes for every iteration of the outer loop.

Key terms

Selection
choosing a block of code based on a condition
Iteration
repeating a block of code
Indentation
leading spaces that define a block in Python
break
a statement that terminates the loop
continue
a statement that skips to the next iteration

Important questions with answers

Distinguish between break and continue.2 marks

break terminates the loop completely and transfers control to the statement after the loop. continue skips the remaining statements of the current iteration and moves to the next iteration of the loop.

Write a program to print the sum of the first n natural numbers using a loop.3 marks

n = int(input('Enter n: ')); total = 0; for i in range(1, n + 1): total += i; then print('Sum =', total). For n = 5, the output is Sum = 15.

Explain the for and while loops in Python with examples and their differences.5 marks

Python provides two looping statements. The for loop is used to iterate over a sequence such as a range of numbers, a string, a list or a tuple. Its syntax is for variable in sequence followed by an indented block. For example, for i in range(1, 6): print(i * i) prints the squares 1, 4, 9, 16 and 25. The range() function can take one, two or three arguments: start, stop and step, and the stop value is not included. The for loop is best when the number of repetitions is known in advance or when processing each element of a sequence. The while loop repeats a block as long as a condition remains True. Its syntax is while condition followed by an indented block. For example, n = 1234; s = 0; while n > 0: s = s + n % 10; n = n // 10 computes the sum of digits, giving 10. The while loop is best when the number of repetitions is not known in advance and depends on a condition. Inside a while loop, the variable controlling the condition must be updated, otherwise an infinite loop occurs. Both loops can use break to exit early and continue to skip an iteration, and both can have an optional else block that runs when the loop ends normally without break. Loops can also be nested to solve problems such as printing patterns and tables.

Quick revision

  • Sequential flow and indentation.
  • if, if-else, if-elif-else.
  • for loop and range().
  • while loop; break, continue; nested loops.

Exam tips

  • Trace range() carefully: the stop value is not included.
  • Always change the loop variable inside a while loop.

Practice MCQs

  1. Python uses which of these to define blocks of code

    1. curly braces
    2. semicolons
    3. indentation
    4. brackets
    Show answer

    Answer: (c) indentation. Usually four spaces.

  2. range(1, 5) generates

    1. 1, 2, 3, 4, 5
    2. 2, 3, 4, 5
    3. 0, 1, 2, 3, 4
    4. 1, 2, 3, 4
    Show answer

    Answer: (d) 1, 2, 3, 4. The stop value is excluded.

  3. The statement that exits a loop immediately is

    1. break
    2. continue
    3. pass
    4. return
    Show answer

    Answer: (a) break. Control moves after the loop.

  4. The output of for i in range(10, 0, -3): print(i, end=' ') is

    1. 9 6 3
    2. 10 7 4
    3. 10 7 4 1
    4. 10 7 4 1 -2
    Show answer

    Answer: (c) 10 7 4 1. Values stop before reaching 0.

  5. The statement that skips the rest of the current iteration is

    1. break
    2. continue
    3. exit
    4. else
    Show answer

    Answer: (b) continue. The loop proceeds to the next iteration.

  6. How many times does the body run in for i in range(2, 11, 2)

    1. 4
    2. 5
    3. 6
    4. 10
    Show answer

    Answer: (b) 5. Values are 2, 4, 6, 8, 10.

  7. What is printed by: i = 1; while i < 10: i = i * 2; then print(i)

    1. 8
    2. 16
    3. 10
    4. 2
    Show answer

    Answer: (b) 16. i becomes 2, 4, 8, 16 and the loop stops.

  8. In a nested loop where the outer loop runs 3 times and the inner loop runs 4 times for each, the inner body runs

    1. 7 times
    2. 12 times
    3. 3 times
    4. 4 times
    Show answer

    Answer: (b) 12 times. 3 × 4 = 12.

All chapters of Class 11 Computer Science

Written by Kundali IQ from standard, well-established facts to help with revision. This is not an official NCERT publication; always read your textbook too.