- Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathtest_continue.py
29 lines (20 loc) · 879 Bytes
/
test_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
"""CONTINUE statement
@see: https://docs.python.org/3/tutorial/controlflow.html
The continue statement is borrowed from C, continues with the next iteration of the loop.
"""
deftest_continue_statement():
"""CONTINUE statement in FOR loop"""
# Let's
# This list will contain only even numbers from the range.
even_numbers= []
# This list will contain every other numbers (in this case - ods).
rest_of_the_numbers= []
fornumberinrange(0, 10):
# Check if remainder after division is zero (which would mean that number is even).
ifnumber%2==0:
even_numbers.append(number)
# Stop current loop iteration and go to the next one immediately.
continue
rest_of_the_numbers.append(number)
asserteven_numbers== [0, 2, 4, 6, 8]
assertrest_of_the_numbers== [1, 3, 5, 7, 9]