-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path12-ContinueBreakPass.py
84 lines (81 loc) · 1.58 KB
/
12-ContinueBreakPass.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#Use of Continue, Break, Pass
'''
terminate the current "iteration" or even the "whole loop" without
checking test expression.
'''
#Continue
#The continue statement is used to skip current iteration
# Program to show the use of continue statement inside loops
#Example1
for val in "string":
if val == "i":
continue
print(val)
'''
s
t
r
n
g
'''
#Example2
for i in range(1, 11):
if i == 5:
continue
print( i," ",end="" )
'''
1 2 3 4 6 7 8 9 10
'''
#Break
'''
The break statement terminates the loop containing it.
If the break statement is inside a nested loop,
the break statement will terminate the innermost loop.
'''
# Use of break statement inside the loop
#Example1
for val in "string":
if val == "i":
break
print(val)
'''
s
t
r
'''
#Example2
n=2
while 1:
i=1;
while i<=10:
print("%d X %d = %d\n"%(n,i,n*i))
i = i+1;
choice = int(input("Do you want to continue printing the table, press 0 for no?"))
if choice == 0:
break
n=n+1
'''
2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
2 X 4 = 8
2 X 5 = 10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 = 20
Do you want to continue printing the table, press 0 for no?
'''
#Pass Statement
'''
In Python programming, the pass statement is a null statement.
The difference between a "comment" and a pass statement in
Python is that while the interpreter ignores a comment entirely,
"pass" is not ignored.
However, nothing happens when the pass is executed.
It results in no operation
'''
sequence = {'p', 'a', 's', 's'}
for val in sequence:
pass