-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2018_12_08_loop.py
More file actions
44 lines (32 loc) · 819 Bytes
/
Copy path2018_12_08_loop.py
File metadata and controls
44 lines (32 loc) · 819 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8 13:58:42 2018
@author: domenjemec
@title: 2018-12-08 Loop
"""
def main():
x = 0
# define a while loop
while (x < 5):
print(x)
x = x + 1
# define a for loop
for x in range(0, 10):
print(x)
# use a for loop over a collection
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for d in days:
print(d)
# use the break and continue statements
for x in range(5, 100):
# if (x == 7): break
if (x % 2 == 0):
continue
print(x)
# using the enumerate() function to get index
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for i, d in enumerate(days):
print(i, d)
if __name__ == "__main__":
main()