Skip to content

Commit 99b0071

Browse files
feat: add readme in loops
1 parent 6b8d052 commit 99b0071

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Reminder/5_loops/readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Loops
2+
## For vs While Loops
3+
### For Loop
4+
- Really great when you want to iterate over something and you need to do something with each thing that you are iterating over.
5+
- Example:
6+
```
7+
fruits = ['Apple', 'Banana', 'Orange']
8+
for fruit in fruits:
9+
print(fruit)
10+
11+
for i in range(1, 6):
12+
print(i)
13+
```
14+
### While Loop
15+
- Use while loop when you don't really care:
16+
- what number in a sequence you are in,
17+
- which item you are iterating through in a list
18+
- You just want to simply carry out some sort of functionality many times until some sort of condition that you set.
19+
- While loops are a bit more dangerous since it can generate infinite loop: sort of condition that actually never becomes false!!!
20+
```
21+
while 5>3:
22+
print('Yes') # this will print "Yes" until the end of time!
23+
```

0 commit comments

Comments
 (0)