+ 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:
5 Answers
+ 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.
+ 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)
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
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.
0
As long as i is more than or equal to 0.