-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_for_loop.py
More file actions
30 lines (21 loc) · 805 Bytes
/
Copy pathpython_for_loop.py
File metadata and controls
30 lines (21 loc) · 805 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
"""
Syntax:
for variable in sequence: 'for' and 'in' are keywords
print("instructions")
"""
for char in "shiva": # looping through a string. Prints each letter of the string in a new line
print(char)
colours = ["orange", "Yellow", "olive", "black"]
for colour in colours: # Prints all the values in an array.
print(colour)
for i in range(6, 15): # prints the numbers (0 - 14)
print(i)
for shade in colours:
if shade == "olive": # if statement breaks the loop to execute a specified condition.
print("olive - Colour of the month!")
else:
print(shade) # if condition untrue, prints the values in the array.
clothes = ["Shirt", "Gown", "Jacket"]
for dress in clothes:
for color in colours:
print(color, dress)