Page 120 - 2611_SmartGPT Pro V(5.0) C-7
P. 120
Let us look at an example:
Program 12. To print the first five natural numbers.
Program12.py Output
File Edit Format Run Options Window Help 1
i=1 2
while i<=5: 3
print(i) 4
i+=1 5
THE INFINITE LOOP
Program 13. To demonstrate the execution of an infinite loop.
Program13.py Output
File Edit Format Run Options Window Help Orange Education
i=1 Orange Education
while(i<10): Orange Education
print("Orange Education") Orange Education
Orange Education
Here, the value of i is not changed and it will always be less than 10, so Orange Education will keep
on printing infinitely.
To exit the infinite loop, you can close the program window. This will break the execution of the
program.
Tick ( ) if you know this.
▶ Iteration means repeating a set of instructions again and again.
▶ The for loop repeats a block of statements a fixed number of times.
JUMP STATEMENTS
Sometimes, you may want to stop a loop early or skip certain steps inside a loop. In such
cases, Python provides jump statements to control the flow of the loop. Python offers two jump
statements—break and continue, which are used within loops.
118 Computer Science (V5.0)-VII

