Page 156 - Information_Practice_Fliipbook_Class11
P. 156
for x in range(1, 5): num = 5
if x == 3: while num <= 10:
continue if num % 4 == 0:
else: num = num + 1
print(x) continue
print('Over') else:
print(num * num)
num = num + 1
print("Done")
Output: Output:
1 25
2 36
4 49
Over 81
100
Done
break and continue statements are usually part of the body of the if statement.
Program 6.9 To accept 5 numbers (except 0) and display their product.
01 #Objective: To accept 5 numbers (except 0) and display their product.
02 P = 1
03 for count in range(1, 6):
04 num=int(input('Enter a number : '))
05 if num == 0:
06 print(' ZERO will not be multiplied')
07 continue
08 P = P * num
09 print('The Product is : ', P)
Sample Output:
>>> Enter a number : 4
>>> Enter a number : -9
>>> Enter a number : 5
>>> Enter a number : 0
ZERO will not be multiplied
>>> Enter a number : -3
The Product is : 540
In program 6.9, if the user enters 0, the continue statement skips the rest of the loop statements and causes the next
iteration of the loop without executing the statement, P = P * num.
6.6 Nested Loops
When a loop appears within another loop, it is called a nested loop. An inner loop is part of the body of the outer
loop. The inner loop is executed win each iteration of the outer loop. Nesting may be continued up to any level. The
following examples will illustrate the use of nested loops.
142 Touchpad Informatics Practices-XI

