Help with the while loop. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Help with the while loop.

Can someone help me with this: i = 3 while i >= 0: print(I) i = i - 1 I know the answer is 4, and the sequence follows 3,2,1,0. What does while i >= 0: stand for? I thought it said: while i is greater than/equal to 0:

24th Jan 2016, 3:10 PM
Jonathan Garland
Jonathan Garland - avatar
5 Respuestas
+ 3
Basically it says greater than or equal to. So the equal to gets counted as well. If it was only greater than, there would be no zero.
4th Feb 2016, 3:59 PM
Kay (Panda)
Kay (Panda) - avatar
+ 2
Yes it means exactly that...and given that i is reducing with 1 with every loop, it will print to 0 and then exit when it gets to -1 (which it will not loop and print)
27th Jan 2016, 8:20 AM
kevin kibet
kevin kibet - avatar
0
while i is greater or equal than 0, it will keep looping. notice that inside while loop there is a statement i=i-1 to decrease the value of i
25th Jan 2016, 11:10 PM
ryo nagato
ryo nagato - avatar
0
It stands exactly for that Jonathan. So starting from 3 until i is greater than OR equal to 0. And so the sequence is 3210.
5th Apr 2016, 3:18 AM
Manoj Papisetty
Manoj Papisetty - avatar
0
As long as i is more than or equal to 0.
13th Apr 2016, 3:22 PM
Zac Hinote
Zac Hinote - avatar