-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor loops
More file actions
30 lines (22 loc) · 937 Bytes
/
for loops
File metadata and controls
30 lines (22 loc) · 937 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
for loops are similair to while loops.
here is an example of one:
for i in range(10):
print(i)
this is a range for loop.
heres a example of what it is saying:
okay, I have ten donuts, for every donut people want me to deliver, I tell them on the phone what delivery number they are.
get it?
this will only print i nine times though, and if you want ten than you would make range 11.
here is another type of four loop:
for x in "banana":
print(x)
this is saying for every letter in the string banana, say that letter.
this will priint banana in a way where the b is on one line, then the a is below it, and the n is below that, and so on.
here is another type of for loop:
fruits = ["pine apple", "banana", "water melon"]
for x in fruits:
print(x)
if x == "banana":
break
this is saying for every string in the fruits list, print the string.
but then it says that if it gets to banana, then break out of the loop.