+ 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")
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")
+ 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
0
first statement not true
- 3
breaking
-6
end of program



