+ 1
Loops? Still not clear, can you help me
How many loops are they, why are they useful, what is the difference between while and for...?
4 Answers
+ 1
Thank you, started getting some light
+ 1
I think there is only 3 kind of loops in Python:
for & while
Ignore 3rd (recursion)
while is very simple, it just repeats it's code until it's condition gets false.
while <This is true>:
<This block of code will run>
for loop is very useful, it can check through any iterable.
for i in ["Hello", "World", "2000000th", "Time"]:
print(i)
In each iteration, i will be assigned to the next item, like any other variable.
Output:
Hello
World
2000000th
Time
0
can you specify what part of loops you do not understand?
0
for loops let you run over an iterable. Can be a string, a list, tuple, range of numbers...
Basically it means:
for every item in that iterable:
do what I wrote here.
Someone else may add the part about while. đ