Page 93 - Computer - 8
P. 93
7 Iterative Statements
in Python
Pre-Processing
• Iterative Statements • Components of a Loop
• For Loop • Use of Range( ) function in For Loop
• While Loop • Jump Statements in a Loop in Python
The statements or instructions in a program or software are executed in a sequential manner. But
sometimes it is necessary to disrupt the sequential execution of statements and divert the execution
control to some other part of the program. Statements that are used to control the flow of execution of
statements in a program are called Control Statements. These are usually of two types:
• Selection Statements • Iterative Statements
You have learned about Selection statements, or Decision Control statements, in Python. These include
the flowing statements:
• If statement • If … Else statement
• If … Elif … Else statement • Nested If … Else ladder statement
Let’s now learn about Iterative statements in Python.
ITERATIVE STATEMENTS
Sometimes, a set of instructions needs to be executed a number of times based
on a specific condition. For example, consider a teacher preparing report cards
of the students in the class. She will write the marks of the first student in the
register, calculate and write the total marks and percentage, and add remarks,
if any. The above steps will be executed until there are no students left in the
register.
The flowchart for the above steps is shown in the image.
Iterative statements are statements that are executed a specified number of times or until a specified
condition is True. Iterative statements are also called Loops.
COMPONENTS OF A LOOP
The main components of a loop are:
• Initialisation of Control Variable: A control variable is usually a numeric variable that counts the
number of times the loop is executed. It is also known as a Counter. It is assigned an initial value,
which is incremented or decremented after every execution of the loop statements.
• Updation of Control Variable: This is the part of the loop where the counter variable is incremented
or decremented.
91