Page 144 - CodePilot V5.0 C7
P. 144
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
2
i=1
3
while i<=5:
4
print(i)
5
i+=1
THE INFINITE LOOP
An infinite loop is a loop that never ends because its condition is always true and never becomes
false. For example, if a loop is supposed to stop when a certain variable reaches a value but that
variable is never changed inside the loop, the condition remains true forever.
Program 13 To demonstrate the execution of an infinite loop.
Program13.py Output
File Edit Format Run Options Window Help Orange Education
Orange Education
i=1
Orange Education
while(i<10):
Orange Education
print("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.
RAPID RECALL Tick ( ) if you know this.
1. Iteration means repeating a set of instructions again and again.
2. The for loop repeats a block of statements a fixed number of times.
142
CodePilot (V5.0)-VII

