-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path29.forloop.py
More file actions
24 lines (21 loc) · 889 Bytes
/
29.forloop.py
File metadata and controls
24 lines (21 loc) · 889 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
# 29. For Loop In Python
"""
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set,
or a string). This is less like the for keyword in other programming languages and works more
like an iterator method as found in other object-orientated programming languages.
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc
# Even strings are iterable objects, they contain a sequence of characters.
# With the break statement we can stop the loop before it has looped through all the items.
"""
for l in "AB":
print(l)
names= ["omar", "ahmed", "ali", "aymen"]
for name in names:
# Exit the loop when x is "ali", but this time the break comes before the print.
# if name == "ali":
# break
if name == "ahmed":
continue
print(name)
if name == "ali":
break