+ 2

what should be the output of this code and why?

i = -7 while i: i = i +1 if i == 2: print("bie") continue if i == -6: print("Breaking") break print(i) print("end of program")

19th Sep 2016, 5:33 PM
bhavya
4 Answers
+ 2
The question is very tricky and like it. The output will be: end of program As first statement 'if' is not true, it will goto the next statement, which is continue. Now, what continue does? it basically break current loop, skip the others instruction in parent loop, go for the next parent loop phase. As it will break whilee loop, as there is no parent loop of while, it will just execute the print("end of program")
20th Sep 2016, 6:18 AM
Md Mizanur Rahman
Md Mizanur Rahman - avatar
+ 1
as the while loop ends at i==0, the first if is never True the continue behind it will always jump back! Is its indent intended? So the only output is: end of program
19th Sep 2016, 8:23 PM
Ralf
0
first statement not true
19th Sep 2016, 5:38 PM
Kamran
- 3
breaking -6 end of program
19th Sep 2016, 5:38 PM
Kamran