Page 98 - Trackpad_V2.1_class8
P. 98
Program 6: To print a selected range of numbers with start and stop values
Program6.py Output
File Edit Format Run Options Window Help 3
4
for i in range (3,7): 5
print(i) 6
Program 7: To print whole numbers from 0 to 4 using only stop value
Program7.py
File Edit Format Run Options Window Help
for i in range (5):
print(i)
On running the above program, we get the following output
Output
0
1
2
3
4
THE 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 8: To demonstrate the use of a while loop
Program8.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)
count += 1 #increment/decrement
96 Trackpad (V2.1)-VIII

