-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfor_while.py
More file actions
50 lines (41 loc) · 705 Bytes
/
for_while.py
File metadata and controls
50 lines (41 loc) · 705 Bytes
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
#!/usr/bin/env python
"""
examples of while and for loops
"""
print "breaking out of a while loop"
x = 0
while True:
print x
if x > 3:
break
x = x + 1
print "breaking out of a for loop"
name = "Chris Barker"
for c in name:
print c,
if c == "B":
break
print "\nI'm done"
print "continue in a for loop"
name = "Chris Barker"
for c in name:
if c == "B":
continue
print c,
print "\nI'm done"
print "continue in a while loop"
x = 6
while x > 0:
x = x-1
if x%2:
continue
print x,
print "\nI'm done"
print "else in a for loop"
x = 5
for i in range(5):
print i
if i == x:
break
else:
print "else block run"