Curriculum
Course: Grade XI Computer Science
Login
Text lesson

Le-6 Flow of Control

School Revise · Class 11 Computer Science · Chapter 6

Flow of Control

Code 083, Class 11. Programs make choices and repeat work. Here we learn if statements for decisions and for and while loops for repetition.

2

Kinds of loop

3

if, elif, else

What this chapter is about

By default Python runs lines top to bottom. To make decisions we use if statements, and to repeat work we use loops. This is called the flow of control.

1. Making decisions with if

An if statement runs a block only when a condition is True. elif checks another condition, and else runs when none are True. The block is indented by four spaces.

n = 8 if n % 2 == 0: print(“even”) else: print(“odd”) Output: even

2. Repeating with for

A for loop repeats over a range of values. range(1, 6) gives 1, 2, 3, 4, 5.

3. Repeating with while

A while loop repeats as long as its condition stays True. Always change something inside so the loop can end. break stops a loop and continue skips to the next round.

Practise with the interactive

Set a condition and a range, and watch which lines run. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Print whether 8 is even or odd.

SOLUTION

n = 8 if n % 2 == 0: print(“even”) else: print(“odd”)

OUTPUT

even
Problem 2. Print the larger of 5 and 9.

SOLUTION

a, b = 5, 9 if a > b: print(a) else: print(b)

OUTPUT

9
Problem 3. Print the numbers 1 to 5, each on its own line.

SOLUTION

for i in range(1, 6): print(i)

OUTPUT

1 2 3 4 5
Problem 4. Print the 3 times table.

SOLUTION

for i in range(1, 11): print(3, “x”, i, “=”, 3 * i)

OUTPUT

3 x 1 = 3 3 x 2 = 6 … up to 3 x 10 = 30
Problem 5. Find the sum of the numbers 1 to 10.

SOLUTION

s = 0 for i in range(1, 11): s = s + i print(s)

OUTPUT

55
Problem 6. Count down from 5 to 1 using while.

SOLUTION

n = 5 while n > 0: print(n) n = n – 1

OUTPUT

5 4 3 2 1
Problem 7. Say if a number is positive, negative or zero.

SOLUTION

n = -4 if n > 0: print(“positive”) elif n < 0: print(“negative”) else: print(“zero”)

OUTPUT

negative
Problem 8. Print the even numbers from 2 to 10.

SOLUTION

for i in range(2, 11, 2): print(i)

OUTPUT

2 4 6 8 10
Problem 9. Find the factorial of 5.

SOLUTION

f = 1 for i in range(1, 6): f = f * i print(f)

OUTPUT

120
Problem 10. Print a right triangle of stars, 4 rows.

SOLUTION

for i in range(1, 5): print(“*” * i)

OUTPUT

* ** *** ****

Practice set A, multiple choice

1. The loop that repeats while a condition is True is the …

while loop.

2. range(1, 6) gives which values?

1, 2, 3, 4, 5. The last number is not included.

3. Which keyword runs when no if or elif condition is True?

else.

4. Which statement stops a loop early?

break.

Quick summary

Programs run top to bottom unless we change the flow. An if statement (with elif and else) makes decisions. A for loop repeats over a range; range(1, n) stops before n. A while loop repeats while a condition is True; break stops a loop and continue skips to the next round. Indent blocks by four spaces.

Open the Virtual Lab

These free Class 11 Computer Science notes explain flow of control, if elif and else decisions, for and while loops, range, break and continue with worked Python programs and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 11 Computer Science syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories