-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreak and continue .py
63 lines (55 loc) · 1.14 KB
/
break and continue .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
breaking of loop
sum=0
for i in range(100):
value= int(input())
if(value<0):
sum=sum+value
print("sum=",sum)
# Using continue
# in continue the loop is not broken it is just skipping certain iteration for a certain number.
# u justneed to write the condition and continue under it to cancel that particular iteration
sum=0
for i in range(100):
value= int(input())
if(value<0):
#-ve number: skip to the next number
#iteration of the loop
continue
sum=sum+value
print("sum=",sum)
i=1
while i<=10:
if i%2==0:
print(i,end="")
i = 1
while i <= 10:
if i%2==0: # even
i= i+1
continue
print (i, end=' ')
i= i+1
i = 1
while i <= 10:
if i%2==0: # even
continue
print (i, end=' ')
i= i+1
r,a,n = 2,10,20
term = a
for i in range(n):
term = term * r
if (i > 3):
break
print (term)
i = 1
while i <= 10:
if i%2==0: # even
i= i+1
continue
print (i, end=' ')
i = 1
while i <= 10:
i= i+1
if i%2==0: # even
continue
print (i, end=' ')