Skip to main content
Chapter 6 of 11
NCERT Solutions

Flow of Control — NCERT Solutions

CBSE · Class 11 · Computer Science

NCERT Solutions for Flow of Control, CBSE Class 11 Computer Science: 16 textbook questions solved step by step.

34 questions72 flashcards5 formulas & key relations5 concepts

Interactive on Super Tutor

Studying Flow of Control? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.

Free trial, no card needed.

16 Questions Solved · 3 Sections

The first 8 solutions are open to read. The other 8 are free with a Super Tutor account.

Exercise

1What is the difference between else and elif construct of if statement?Show solution

Given: Two constructs of the if statement — else and elif.

Concept: Both are used with the if statement for decision making, but they serve different purposes.

Featureelseelif
Full formelseelse if
ConditionDoes not take any conditionTakes a condition to test
PurposeExecutes when the if (and all preceding elif) conditions are FalseExecutes when its own condition is True and all previous conditions are False
Number of times usedOnly once at the end of an if blockCan be used multiple times
AlternativeProvides a single alternativeProvides multiple alternatives

Example:

# Using else
x = 5
if x > 10:
    print("Greater than 10")
else:
    print("Not greater than 10")   # This executes

# Using elif
marks = 75
if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")   # This executes
elif marks >= 60:
    print("Grade C")
else:
    print("Grade D")

Conclusion: else provides one alternative when the if condition is False, whereas elif allows checking multiple conditions in sequence.

2What is the purpose of range() function? Give one example.Show solution

Purpose of range() function:

The range() function is used to generate a sequence of integers. It is commonly used with the for loop to repeat a block of code a specific number of times.

Syntax:
range(start, stop, step)\text{range(start, stop, step)}

  • start — Starting value of the sequence (default is 0)
  • stop — The sequence goes up to stop - 1 (this value is not included)
  • step — Difference between each number in the sequence (default is 1)

Example:

for i in range(1, 10, 2):
    print(i)

Output:

1
3
5
7
9

Explanation: The range(1, 10, 2) generates the sequence 1,3,5,7,91, 3, 5, 7, 9 — starting from 1, ending before 10, with a step of 2. The for loop iterates over each value in this sequence.

3Differentiate between break and continue statements using examples.Show solution

Given: Two loop control statements — break and continue.

Difference:

Featurebreakcontinue
PurposeTerminates the loop immediatelySkips the current iteration and moves to the next
Control flowExits the loop entirely; execution continues with the statement after the loopJumps back to the beginning of the loop for the next iteration
Remaining iterationsAll remaining iterations are skippedRemaining iterations continue to execute

Example of break:

for i in range(1, 6):
    if i == 3:
        break
    print(i)

Output:

1
2

Explanation: When i becomes 3, the break statement exits the loop. Values 3, 4, 5 are never printed.

Example of continue:

for i in range(1, 6):
    if i == 3:
        continue
    print(i)

Output:

1
2
4
5

Explanation: When i becomes 3, the continue statement skips the print for that iteration and moves to i = 4. All other values are printed normally.

4What is an infinite loop? Give one example.Show solution

Definition:
An infinite loop is a loop that never terminates because its loop condition always remains True and never becomes False. This is a logical error in the program. The statements within the body of the loop must ensure that the condition eventually becomes False; if they do not, the loop runs forever.

Cause: Usually occurs when the loop variable is not updated correctly inside the loop body.

Example:

i = 1
while i > 0:
    print(i)
    i = i + 1   # i keeps increasing, condition i > 0 is always True

Explanation:

  • Initially i = 1, so the condition i > 0 is True.
  • Inside the loop, i is incremented by 1 each time.
  • Since i always remains positive (and keeps growing), the condition i > 0 never becomes False.
  • Therefore, this loop runs indefinitely — it is an infinite loop.

Another simple example:

while True:
    print("This runs forever")
5Find the output of the following program segments:
(i) a = 110
while a > 100:
print(a)
a -= 2

(ii) for i in range(20,30,2):
print(i)

(iii) country = 'INDIA'
for i in country:
print(i)

(iv) i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print(sum)

(v) for x in range(1,4):
for y in range(2,5):
if x * y > 10:
break
print(x * y)

(vi) var = 7
while var > 0:
print('Current variable value: ', var)
var = var - 1
if var == 3:
break
else:
if var == 6:
var = var - 1
continue
print("Good bye!")
Show solution

(i)

a = 110
while a > 100:
    print(a)
    a -= 2

Trace:

  • Iteration 1: a = 110, condition 110 > 100 → True → print 110, a = 108
  • Iteration 2: a = 108, condition 108 > 100 → True → print 108, a = 106
  • Iteration 3: a = 106, condition 106 > 100 → True → print 106, a = 104
  • Iteration 4: a = 104, condition 104 > 100 → True → print 104, a = 102
  • Iteration 5: a = 102, condition 102 > 100 → True → print 102, a = 100
  • Iteration 6: a = 100, condition 100 > 100 → False → loop ends

Output:

110
108
106
104
102

(ii)

for i in range(20, 30, 2):
    print(i)

Trace: range(20, 30, 2) generates: 20, 22, 24, 26, 28

Output:

20
22
24
26
28

(iii)

country = 'INDIA'
for i in country:
    print(i)

Trace: The for loop iterates over each character of the string 'INDIA'.

Output:

I
N
D
I
A

(iv)

i = 0; sum = 0
while i < 9:
    if i % 4 == 0:
        sum = sum + i
    i = i + 2
print(sum)

Trace:

ii < 9i % 4 == 0sumi after update
0TrueTrue (0%4=0)0+0=02
2TrueFalse (2%4=2)04
4TrueTrue (4%4=0)0+4=46
6TrueFalse (6%4=2)48
8TrueTrue (8%4=0)4+8=1210
10False——loop ends

Output:

12

(v)

for x in range(1, 4):
    for y in range(2, 5):
        if x * y > 10:
            break
        print(x * y)

Trace:

  • x = 1:
  • y=2: 1×2=2, 2>10? No → print 2
  • y=3: 1×3=3, 3>10? No → print 3
  • y=4: 1×4=4, 4>10? No → print 4
  • x = 2:
  • y=2: 2×2=4, 4>10? No → print 4
  • y=3: 2×3=6, 6>10? No → print 6
  • y=4: 2×4=8, 8>10? No → print 8
  • x = 3:
  • y=2: 3×2=6, 6>10? No → print 6
  • y=3: 3×3=9, 9>10? No → print 9
  • y=4: 3×4=12, 12>10? Yes → break (inner loop ends)

Output:

2
3
4
4
6
8
6
9

(vi)

var = 7
while var > 0:
    print('Current variable value: ', var)
    var = var - 1
    if var == 3:
        break
    else:
        if var == 6:
            var = var - 1
            continue
print("Good bye!")

Trace:

  • Iteration 1: var=7, condition True → print Current variable value: 7, var=6
  • var==3? No → else: var==6? Yes → var=5, continue (go back to loop start)
  • Iteration 2: var=5, condition True → print Current variable value: 5, var=4
  • var==3? No → else: var==6? No → (no action, loop continues normally)
  • Iteration 3: var=4, condition True → print Current variable value: 4, var=3
  • var==3? Yes → break (exit loop)
  • After loop: print Good bye!

Output:

Current variable value:  7
Current variable value:  5
Current variable value:  4
Good bye!

Programming Exercises

1Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years).Show solution

Concept: Use if-else to compare the entered age with the eligible age of 18.

Program:

# Program to check eligibility for driving license
name = input("Enter your name: ")
age = int(input("Enter your age: "))

if age >= 18:
    print("Hello", name + ", you are eligible to apply for a driving license.")
else:
    print("Hello", name + ", you are NOT eligible to apply for a driving license.")
    print("You need to wait for", 18 - age, "more year(s).")

Sample Output 1:

Enter your name: Riya
Enter your age: 20
Hello Riya, you are eligible to apply for a driving license.

Sample Output 2:

Enter your name: Arjun
Enter your age: 16
Hello Arjun, you are NOT eligible to apply for a driving license.
You need to wait for 2 more year(s).
2Write a function to print the table of a given number. The number has to be entered by the user.Show solution

Concept: Define a function that accepts a number and uses a for loop with range() to print the multiplication table.

Program:

# Function to print multiplication table
def print_table(n):
    print("Multiplication table of", n)
    for i in range(1, 11):
        print(n, "x", i, "=", n * i)

# Main program
num = int(input("Enter a number: "))
print_table(num)

Sample Output:

Enter a number: 5
Multiplication table of 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
3Write a program that prints minimum and maximum of five numbers entered by the user.Show solution

Concept: Accept five numbers from the user using a loop, then use if conditions to track the minimum and maximum values.

Program:

# Program to find minimum and maximum of five numbers
print("Enter 5 numbers:")

# Read the first number to initialise min and max
num = int(input("Number 1: "))
min_num = num
max_num = num

for i in range(2, 6):
    num = int(input("Number " + str(i) + ": "))
    if num < min_num:
        min_num = num
    if num > max_num:
        max_num = num

print("Minimum number =", min_num)
print("Maximum number =", max_num)

Sample Output:

Enter 5 numbers:
Number 1: 34
Number 2: 12
Number 3: 56
Number 4: 7
Number 5: 45
Minimum number = 7
Maximum number = 56
4Write a program to check if the year entered by the user is a leap year or not.

Free with a Super Tutor account

5Write a program to generate the sequence: -5, 10, -15, 20, -25... upto n, where n is an integer input by the user.

Free with a Super Tutor account

6Write a program to find the sum of 1+18+127+1n31 + \frac{1}{8} + \frac{1}{27} + \frac{1}{n^3}, where n is the number input by the user.

Free with a Super Tutor account

7Write a program to find the sum of digits of an integer number, input by the user.

Free with a Super Tutor account

8Write a function that checks whether an input number is a palindrome or not.
[Note: A number or a string is called palindrome if it appears same when written in reverse order also. For example, 12321 is a palindrome while 123421 is not a palindrome]

Free with a Super Tutor account

9Write a program to print the following patterns:
i) Diamond/Rhombus pattern with *
ii) Number pattern: 1 / 2 1 2 / 3 2 1 2 3 / ...
iii) Descending number triangle
iv) Right-angled triangle with *

Free with a Super Tutor account

10Write a program to find the grade of a student when grades are allocated as given in the table below.
Percentage of Marks | Grade
Above 90% | A
80% to 90% | B
70% to 80% | C
60% to 70% | D
Below 60% | E
Percentage of the marks obtained by the student is input to the program.

Free with a Super Tutor account

Case Study-based Questions

6.1Write a menu driven program that has options to:
- Accept the marks of the student in five major subjects in Class X and display the same.
- Calculate the sum of the marks of all subjects. Divide the total marks by number of subjects (i.e. 5), calculate percentage = total marks/5 and display the percentage.
- Find the grade of the student as per the following criteria:
percentage > 85 → A
percentage < 85 && percentage >= 75 → B
percentage < 75 && percentage >= 50 → C
percentage > 30 && percentage <= 50 → D
percentage < 30 → Reappear

Free with a Super Tutor account

8 more solved questions in Flow of Control

They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.

Frequently Asked Questions

What are the important topics in Flow of Control for CBSE Class 11 Computer Science?
Key topics in Flow of Control include Flow of Control and Sequence Execution, Selection Statements, Indentation in Python, Repetition and Loops. Study these first, then practise questions on each for Class 11 exams.
Are these NCERT Solutions for Flow of Control free?
The first 8 of the 16 solutions on this page are open to read. The other 8 are free with a Super Tutor account — signing up is free and needs no card.
How should I revise Flow of Control for Class 11 exams?
Learn the core ideas first, then work through the 34 practice questions on Flow of Control. Revise definitions regularly and use flashcards for quick recall before the exam.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Flow of Control chapter — start free.

Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 11 Computer Science. Free to start, no card needed.