Skip to content

Commit 4dd896b

Browse files
committed
Add break and continue statements example
1 parent f454c1c commit 4dd896b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

flow/other_statement/break.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import math
2+
3+
n = 20
4+
for i in range(2, n):
5+
for j in range(2, int(math.sqrt(i) + 1)):
6+
if i % j == 0:
7+
print(i, 'has a prime factor', j)
8+
break
9+
else:
10+
print(i, 'is a prime number')

flow/other_statement/continue.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
strings = ['dragon',
2+
'internationalization',
3+
'supersymmetry',
4+
'Python',
5+
'nightmare',
6+
'contribution',
7+
'mass']
8+
n = 10
9+
10+
print('list:', strings)
11+
print('10 letters or short words:')
12+
for w in strings:
13+
if len(w) > 10:
14+
continue
15+
print(w)

0 commit comments

Comments
 (0)