Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
Chapter 5. Flow of Control
5.1 Introduction
5.2 Types of statement in python
5.3 Statement Flow Control
5.4 Loops/Iteration
5.5 The range() Function
5.1 Introduction
A program control statement is a type of instruction in programming languages that directs the
flow of execution of a program. These statements determine the order in which the program's
code executes, allowing for decision-making, looping, and branching based on conditions.
5.2 Types of statement in python
a) Empty statement (Null Statement) : The Simplest statement is the empty statement i.e.
statement which does nothing. In python an empty statement is pass statement. It takes
following form:
pass
b) Simple statement (Single statement): Any single executable statement is a simple
statement in Python. For example following simple statement in python:
name=input(“Your name”)
another example of simple statement is:
print(name) # print function called
c) Compound Statement: A compound statement represented a group of statements executed
as a unit. The compound statements of python are written in a specific pattern as shown below:
<compound statement header>:
<indented body containing multiple simple and /or compound statement>
That is, a compound statement has :
➢ A header line which begins with a keyword and ends with a colon.
➢ A body consisting of one or more python statements, each indented inside the header
line. All statements in the body are the same level of indentation.
Compound statement includes( if, for)
5.3 Flow Control Statement:
if- else, for loop→ A control statement is a statement that determines whether other
statement will be executed.
An if statement decides whether to execute another statement, or decides which of two
statement to execute.
A loop decides how many times to execute another statement.
DR. UMME KULSUM [IT DEPT , PGT] 1
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
If-else statement→The if/else statement is a part of Java script’s “condition” statement, which
are used to perform different actions based on different conditions.
Types of
statement
execution in
program
Sequence Selection Iteration
if if else if elif
1) Sequence: The sequence construct means statement are being executed sequentially.
This represents the default flow of statement.
➢ Every python program begins with the first statement of program. Each statement in
turn is executed (sequence construct).
➢ When the final statement of program is executed, the program is done.
➢ Sequence refers to the normal flow of control in a program and is the simplest one.
2) Selection: The selection construct means the execution of statement(s) depending upon
a condition-test.
If a condition evaluates to true, a set of statement is followed otherwise another set of
statement followed.
This construct (selection construct) is also called decision construct because it helps in
making decision about which set-of-statement is to be executed.
Types of selection statement:-
1. The if statement
2. The if-else statement
3. The if-elif statement
4. The nested if statement
DR. UMME KULSUM [IT DEPT , PGT] 2
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
I. The if statement:-
If statement executes the statement(s) inside if when the condition is true.
if condition :
Statement 1
Program to check person is eligible for vote.
age=int(input (“enter your age”))
if age>=18:
print (“eligible to vote”)
O/P:- enter age 19
Eligible to vote.
Note:- if the condition is false it will not show any output.
II. The if-else statement
if-else statement executes the statement(s) inside if when the condition is true, otherwise
executes the statement(s) inside else (when the condition is false).
Test expression
Body of if
Syntax:-
if<condition expression>
Statement
[Statement]
else:
Statement
[Statement]
Example:-
# To check whether you are eligible for vote or not?
age=int (input (“Enter your age :”))
if age>=18:
DR. UMME KULSUM [IT DEPT , PGT] 3
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
print(“Eligible to vote ”)
else:
print(“Not eligible to vote ”)
O/p:-
Enter your age : 19
Eligible to vote
Enter your age: 17
Not eligible to vote
III. The if-elif statement:-
If-elif-else is use to check multiple condition and execute statement accordingly.
Meaning of elif is else-if. We can also write else if instead of elif for more clarity.
Syntax:-
if <condition expression>:
Statement
[Statement]
elif <condition expression>:
Statement
[Statement]
else:
Statement
[Statements]
Example:-
# To Check whether a number is positive, negative or zero.
number=int (input (“Enter a number”))
if number>0:
print (“Number is positive”)
DR. UMME KULSUM [IT DEPT , PGT] 4
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
elif number<0:
print (“number is negative”)
else:
print (“number is zero”)
O/p:-
Enter a number 5
Number is position
Enter a number 0
Enter a number 0
Number is zero.
IV. The nested if statement:-
A nested if is an if that has another if in its if’s body or in elif ’s body or in it else’s body.
Syntax:-
if <condition statement>:
Statement(s)
else:
Statement(s)
elif <condition expression>:
if<condition expression>
Statement(s)
else:
Statement(s)
else:
if <condition expression>
Statement(s)
else:
DR. UMME KULSUM [IT DEPT , PGT] 5
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
Statement(s)
Example:
ch=input(“Enter a single character:”)
if ch>=’A’ and ch<=’Z’:
print(“You entered an upper case character:”)
elif ch>=”a” and ch<=’z’:
print(“You entered a lower case character”)
elif ch>= ‘0’ and ch <=’9’:
print(“You entered a digit”)
else:
print(“You entered a special character”)
Output:
Enter a single character : A
You entered an upper case character:
Enter a single character :0
You entered a digit
5.4 Loops/ iteration:-
Sometimes we need to repeat certain things for a particular number of times. For example, a
program has to display attendance for every student of a class.
➢ Here the program has to execute the print statement for every student. In programming,
this kind of repetition is called looping or iteration.
➢ The iteration constructs mean repetition of a set-of-statement depending upon a
condition is true (or false depending upon the loop), a set=of=statements are repeated
again and again.
➢ As soon as the condition becomes false (or true), the repetition stops.
➢ The iteration construct is also called looping construct.
Types of iteration/Looping statements
Python provides two kinds of loops; for loop and while loop is represent two categories of loops,
which as:
DR. UMME KULSUM [IT DEPT , PGT] 6
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
o Counting loops
o Conditional loops
1. Counting loops:-
The loops that repeat a certain number of times, python for loop is a counting loop.
2. Conditional loops:-
The loops that repeat until a certain thing happens i.e. they keep repeating as long as
some condition is true, python while loop is condition loop.
For loop:-
➢ The For statement is used to iterate over a range of values or a sequence.
➢ The loop is executed for each item in the range. The values can be numeric,
string, list or tuple.
➢ When all the items, in the range are exhausted the statement within loop are not
executed and python interpreter starts executing the statements immediately
following the For loop.
➢ While using for loop, we should know in advance the number of times the loop
will execute.
Syntax:-
for <control-variable> in <sequence/items in range>:
<Statements inside body of the loop>
Example:-
# Program to print even numbers in a given sequence using for loop.
number=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for num in number:
if (num%2)==0:
print (num, ‘is an even number’)
O/p:-
2 is an even number
4 is an even number
6 is an even number
8 is an even number
10 is an even number
While loop:
DR. UMME KULSUM [IT DEPT , PGT] 7
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
A while loop in python is used to repeat a block of code as long as condition is True. When the
condition becomes False, the loop stops.
Syntax:
while condition:
# code block
Example
i=1
while i<=5:
print(i)
i=i+1
O/P: 1
Infinite loop:
i='hello'
while i=='hello':
print(i)
hello
hello
hello
hello
hello
DR. UMME KULSUM [IT DEPT , PGT] 8
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
using break with loop
i='hello'
while i=='hello':
print(i)
break
print(i)
O/P: hello
hello
5.5 The range () function:-
➢ The range () is a built-in function in python.
➢ Syntax of range () function is:
➢ Range ([start], stop [step])
➢ It is used to create a list containing a sequence of integers from the given start value up
to stop value (excluding stop value), with a difference of thr given step value.
➢ If starts value is not specified, by default the list start from 0. If step is also not specified,
by default the value is incremented by 1 in each iteration.
➢ All parameters of range () function must be integers. The step parameter can be a
position or a negative integer excluding zero.
Example:-
List (range (10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Start value is given as 2
List (range (2, 10))
[2, 3, 4, 5, 6, 7, 8, 9]
Step value is 5 and start value is 0
List (range (0, 30 and 5))
[0, 5, 10, 15, 20, 25]
Step value -1. Hence, decreasing
DR. UMME KULSUM [IT DEPT , PGT] 9
Class XI Informatics Practices (065) [2025-26] UNIT 2 Python
Sequence is generated
List (range (0, -9, -1))
[0, -1, -2, -3, -4, -5, -6, -7, 8]
The function range () is often used in for loops for generating a sequence of numbers.
Example:-
# Program to print the multiple of 5 for numbers in a given range.
num=int (input (“Enter number”))
for a in range (1, 11)
int (num, ‘*’, a, ‘=’, num*a)
o/p:-
Enter number=5
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50
DR. UMME KULSUM [IT DEPT , PGT] 10