0

please, won't this code give the same result. i=0 while i<=5 print(i) i+=1 print("finished") and i=0 while 1==1 print(i) i+=1 if i<=5 print ("finished")

21st Sep 2016, 11:16 AM
David Nzere
David Nzere - avatar
8 ответов
+ 2
see after the if statement in last but one line there is no break statement to come out of the loop and also you should only mention if i==5: break ....... I hope you get the difference
21st Sep 2016, 12:45 PM
yashas ND
+ 1
2nd code will run forever if you don't include a break condition
4th Oct 2016, 7:57 PM
Ben Ntabo
Ben Ntabo - avatar
0
The bottom code: While 1 == 1. Do you mean for the variable to be i?
21st Sep 2016, 12:06 PM
Jamie Lewis
Jamie Lewis - avatar
0
you wont get out of the loop.in 2nd one
21st Sep 2016, 1:50 PM
Mehrukh Kamal
Mehrukh Kamal - avatar
0
the loop would never terminate as 1 is always equal to 1 and there is no break statement for if
22nd Sep 2016, 12:08 PM
Pruthvi Raj
0
no break are used
28th Sep 2016, 7:07 PM
Thameshwar Sinha
Thameshwar Sinha - avatar
0
you second loop says each iteration less or equal 5 print (finished) then the loop continues to infinity adding +1 each iteration
29th Sep 2016, 11:22 AM
Umar Muhummed
Umar Muhummed - avatar
- 1
The if statement in the second code must have a break statement to go out of loop.
27th Sep 2016, 1:24 PM
Sounak Das
Sounak Das - avatar