
11.1K
PYPython Loops: Breaking Out of While Loops!
Learn how to use the `break` statement in a `while` loop with this simple Python MCQ.
Ready for a Python challenge? Test your skills with this brain-teasing question:
What will be the output of the following code?
i = 0
while i < 4:
print(i)
if i == 2:
break
i += 1
A) 0 1 2 B) 0 1 2 3
C) 0 1 2 3 4 D) 1 2 3
Answer
A) 0 1 2
Explanation
The loop prints the value of `i` and breaks when `i` is 2, so the output is `0 1 2`.
Drop your answers in the comments! Let's see who can crack this Python puzzle! Don't forget to engage with us using these hashtags:
#codeaj
#codeajay
#PythonMCQ
#Programming
#CodingChallenge
#codingCommunity
#codingQuiz
#programmingChallenge
#ProgrammingLanguages
#learncoding
#python
#pythoncoding
#Softwaredevelopment
#coders
#PythonCoding4U
@pythoncoding4u










