What is the output of the following snippet?
i=1
while True:
if i%3 ==0:
break
print(i,end=")
i +=1
Answers
Answered by
7
Answer:
1 2
Explanation:
Check the attachment given below.
Language: Python.
As a is initially assigned with 1,
In "while True:", as the condition is always True, the only way to terminate it is to use unconditional statements (as break in if statement)
When i=1, the if condition 1%3==0 becomes false and 1 is printed, while i gets incremented.
Similarly, When i=2, the if condition 2%3==0 becomes false and 2 is printed, while i gets incremented.
But, when i=3, the if condition 3%3==0 becomes true and break statement gets executed, resulting in the termination of loop.
So, the output is 1 2
Attachments:
Similar questions