Page 497 - ComputerScience_Class_11
P. 497
12.3.3 Iterative Statements
Iterative statements, also known as loops, allow a program to execute a block of code repeatedly, based on a condition.
These statements are essential when you want to perform the same task multiple times without rewriting the same code.
The variable which changes its value until a given condition is true in short which controls the loop is known as control
variable.
Parts of a Loop
Each looping structure has the following parts:
• Initialization of the control variable
• Checking test condition
• Body of the loop
• Updating the control variable
A loop can be further subdivided into two parts based on iteration:
Iterative Statements
A loop can be further subdivided into two parts based on iteration:
• Fixed iteration: When the number of repetitions is known in advance, it is called fixed iteration or definite iteration.
It has the following characteristics:
o Number of times is pre-decided
o Uses for loop
o Controlled by a range or sequence
• Unfixed iteration: When the number of repetitions is not known in advance, it is called unfixed iteration or indefinite
iteration. The properties of unfixed iteration are:
o Number of times depends on a condition
o Uses while loop
o Stops when condition becomes false
In entry-controlled loops the control enters the body of the loop only when the condition evaluates true. If the condition
is false, it exists the loop. Both for and while loops are entry-controlled loops.
Python does not have exit-controlled loops like do..while , repeat..until
The for Loop
The for loop is a type of iterative statement in Python that allows you to repeat a block of code to a specific number of
times or iterate over a sequence (like a list, tuple, string or range). It is commonly used when the number of iterations
is known beforehand or when you want to process each item in a sequence one by one.
Syntax:
for variable in sequence:
statement
where:
• variable: loop control variable
• sequence: range, list, string, tuple, dictionary
Flow of Control 495

