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.
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.
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.
| Feature | else | elif |
|---|---|---|
| Full form | else | else if |
| Condition | Does not take any condition | Takes a condition to test |
| Purpose | Executes when the if (and all preceding elif) conditions are False | Executes when its own condition is True and all previous conditions are False |
| Number of times used | Only once at the end of an if block | Can be used multiple times |
| Alternative | Provides a single alternative | Provides 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:
start— Starting value of the sequence (default is 0)stop— The sequence goes up tostop - 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
9Explanation: The range(1, 10, 2) generates the sequence — 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:
| Feature | break | continue |
|---|---|---|
| Purpose | Terminates the loop immediately | Skips the current iteration and moves to the next |
| Control flow | Exits the loop entirely; execution continues with the statement after the loop | Jumps back to the beginning of the loop for the next iteration |
| Remaining iterations | All remaining iterations are skipped | Remaining iterations continue to execute |
Example of break:
for i in range(1, 6):
if i == 3:
break
print(i)Output:
1
2Explanation: 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
5Explanation: 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 TrueExplanation:
- Initially
i = 1, so the conditioni > 0isTrue. - Inside the loop,
iis incremented by 1 each time. - Since
ialways remains positive (and keeps growing), the conditioni > 0never 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 -= 2Trace:
- Iteration 1:
a = 110, condition110 > 100→ True → print 110,a = 108 - Iteration 2:
a = 108, condition108 > 100→ True → print 108,a = 106 - Iteration 3:
a = 106, condition106 > 100→ True → print 106,a = 104 - Iteration 4:
a = 104, condition104 > 100→ True → print 104,a = 102 - Iteration 5:
a = 102, condition102 > 100→ True → print 102,a = 100 - Iteration 6:
a = 100, condition100 > 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:
i | i < 9 | i % 4 == 0 | sum | i after update |
|---|---|---|---|---|
| 0 | True | True (0%4=0) | 0+0=0 | 2 |
| 2 | True | False (2%4=2) | 0 | 4 |
| 4 | True | True (4%4=0) | 0+4=4 | 6 |
| 6 | True | False (6%4=2) | 4 | 8 |
| 8 | True | True (8%4=0) | 4+8=12 | 10 |
| 10 | False | — | — | 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 → printCurrent 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 → printCurrent variable value: 5,var=4 var==3? No → else:var==6? No → (no action, loop continues normally)- Iteration 3:
var=4, condition True → printCurrent 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 = 503Write 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 = 56Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
[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
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
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
- 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?
Are these NCERT Solutions for Flow of Control free?
How should I revise Flow of Control for Class 11 exams?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Flow of Control
Practice Quiz
Test yourself with a quick quiz
Important Questions
Exam-style questions with answers
Revision Notes
Key points for last-minute revision
Formula Sheet
The chapter's formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect
Study Plan
Step-by-step plan for this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
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.