0

Explain the difference In Infinte Loops Code

Code 1 i = 0 while 1==1: i = i + 1 print(i) if i >= 5: print("Breaking") break print("Finished") Code 2 i = 0 while 1==1: print(i) i = i + 1 if i >= 5: print("Breaking") break print("Finished")

25th Apr 2020, 3:18 PM
Ojo Sampson
Ojo Sampson - avatar
2 Réponses
+ 3
Your loops are not infinite, as you have a reachable base case wich break the loop when i >= 5 ^^ Anayway, the only difference between your two snippets is the print function, wich occurs respectively after or before incrementing i ;P
25th Apr 2020, 4:09 PM
visph
visph - avatar
+ 1
There is code playground ,use it
25th Apr 2020, 4:10 PM
Abhay
Abhay - avatar