0

What is the difference between two result?

The example is i = 0 while 1==1: print(i) i = i + 1 if i >= 5: print("Breaking") break print("Finished") And my answer is 0 Finished 1 Finished 2 Finished 3 Finished 4 Breaking but, the solution is >>> 0 1 2 3 4 Breaking Finished >>> what is the difference those answers?? please save me lol :(

3rd May 2020, 6:32 AM
Naehyun(Ray) Park
5 Answers
+ 2
Indentation of the last print statement should be a problem
3rd May 2020, 6:34 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 very true. Its while i < 4. What I'm trying to nail home is the principle of indentation and the part it plays in loops.
3rd May 2020, 6:56 AM
Slick
Slick - avatar
0
Infinity is right. And its your while loop. while 1 == 1 is a loop that'll go on forever. Try: while i < 5. The only way it would print finished every iteration is if it was IN the while loop. print('Finished') is fine in the example you gave.
3rd May 2020, 6:46 AM
Slick
Slick - avatar