+ 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...?

31st Jul 2019, 1:24 PM
rime
4 Answers
+ 1
Thank you, started getting some light
31st Jul 2019, 2:15 PM
rime
+ 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
31st Jul 2019, 4:11 PM
Seb TheS
Seb TheS - avatar
0
can you specify what part of loops you do not understand?
31st Jul 2019, 1:43 PM
Pikachu
Pikachu - avatar
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. 😉
31st Jul 2019, 2:04 PM
HonFu
HonFu - avatar