Page 92 - KEC Khaitan C8 Flipbook
P. 92
On running the above program, we get the following output:
Output
0
1
2
3
4
while LOOP
The while loop repeats a block of statements while a given condition is true. In this looping
construct, first, the condition is checked and if it is true, the control will move inside the loop and
execute the statements until the condition becomes false. If the initial condition is false, then the
control will not enter the loop block. The syntax of while loop is as follows:
while(condition):
statement(s)
increment/decrement
Program 4: To demonstrate the use of a while loop
Program4.py
File Edit Format Run Options Window Help
#Program to demonstrate the use of a while loop
# Initialize a variable
count = 1
#test expression
while count < 5:
print("Count is:", count)
#increment/decrement
count += 1
On running the above program, we get the following output:
Output
Count is: 1
Count is: 2
Count is: 3
Count is: 4
90 Premium Edition-VIII

