File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments