-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathloops.py
More file actions
91 lines (81 loc) · 1.19 KB
/
loops.py
File metadata and controls
91 lines (81 loc) · 1.19 KB
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
85
86
87
88
89
90
91
# Copyright 2018 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
doc="While"
a = 1
while a < 10:
a += 1
assert a == 10
doc="While else"
a = 1
ok = False
while a < 10:
a += 1
else:
ok = True
assert a == 10
assert ok
doc="While break"
a = 1
ok = True
while True:
if a >= 10:
break
a += 1
else:
ok = False
assert a == 10
assert ok
doc="While continue"
a = 1
while a < 10:
if a == 5:
a += 1000
continue
a += 1
assert a == 1005
doc="For"
a = 0
for i in (1,2,3,4,5):
a += i
assert a == 15
doc="For else"
a = 0
ok = False
for i in (1,2,3,4,5):
a += i
else:
ok = True
assert a == 15
assert ok
doc="For break"
a = 0
ok = True
for i in (1,2,3,4,5):
if i >= 3:
break
a += i
else:
ok = False
assert a == 3
assert ok
doc="For continue"
a = 0
for i in (1,2,3,4,5):
if i == 3:
continue
a += i
assert a == 12
doc="For continue in try/finally"
ok = False
a = 0
for i in (1,2,3,4,5):
if i == 3:
try:
continue
finally:
ok = True
a += i
assert a == 12
assert ok
doc="finished"