forked from bradtraversy/python_sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.py
More file actions
33 lines (25 loc) · 697 Bytes
/
loops.py
File metadata and controls
33 lines (25 loc) · 697 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
# A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
people = ['John', 'Paul', 'Sara', 'Susan']
# Simple for loop
for person in people:
print(f'Current Person: {person}')
# Break
for person in people:
if person == 'Sara':
break
print(f'Current Person: {person}')
# Continue
for person in people:
if person == 'Sara':
continue
print(f'Current Person: {person}')
# range
for i in range(len(people)):
print(people[i])
for i in range(0, 11):
print(f'Number: {i}')
# While loops execute a set of statements as long as a condition is true.
count = 0
while count < 10:
print(f'Count: {count}')
count += 1