Page 144 - TP_Prime_V2.2_Class8
P. 144
In the above example, the initial value is 1. The final value is 100 and the incremental value
is 5. The next number is 105, which is outside the range, and therefore, the program comes
out of loop.
Program 4: To print all the even numbers upto the number entered by the user.
Output
Prime (Ver. 2.2)-VIII File Program4.py Run Options Window Help 0
enter number
2
Format
Edit
4
6
x=int(input("enter number"))
8
for x in range (0,a,2):
10
print(x)
142 Program 5: To print the table of 13. 12
Output
13
26
39
Program5.py 52
65
File Edit Format Run Options Window Help 78
a=13 91
for x in range (1,11,1): 104
b=a*x 117
print(b) 130
The loop continues to execute until the condition is achieved. Let us see how this was
achieved:
Step 1: Initialise the variable a with the value 13.
Step 2: Execute the for loop with initial value as 1 and final value as 11 and The loop
increments by 1 each time.
Step 3: Store the multiplication answer in another variable b.
Step 4: Print the value of b for each iteration.
The while Loop
A while loop is used when the number of iterations are not known to the user before running
the loop. As long as the condition given is True, the loop will continue to repeat.

