While Loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

While Loops

i = 0 while 1 == 1: i += 1 print(i) if i >= 5: break print("Almost Done.") print("Finish!") Why this code DISPLAY 1,2,3,4,5 but i = 0 while 1 == 1: Print(I) i += 1 if i >= 5: break print("Almost Done.") print("Finish!") DISPLAY 0,1,2,3,4

19th May 2020, 9:35 PM
BlackChain
BlackChain - avatar
2 Answers
+ 2
BlackChain couse you change place for I+=1 And Print(i)
19th May 2020, 9:41 PM
Petr
+ 1
The code is producing what it reads. In your second code, you are asking it to print the output before i+=1, so it starts from 0
19th May 2020, 10:13 PM
Rik Wittkopp
Rik Wittkopp - avatar