निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
i = 2
while True:
if i%3 == 0:
break
print(i,end=" " )
i += 2 A
2 4 6 8 10 ..
B
2 4
C
2 3
D
error
Explanation
Let's break down the code:
i = 2
while True:
if i % 3 == 0:
break
print(i, end=" ")
i += 2
Step-by-step execution:
-
i = 2: We start withi = 2. -
First iteration:
i % 3 == 0isFalsebecause2 % 3 == 2.print(i, end=" ")prints2.i += 2makesi = 4.
-
Second iteration:
i = 4, soi % 3 == 0is stillFalsebecause4 % 3 == 1.print(i, end=" ")prints4.i += 2makesi = 6.
-
Third iteration:
i = 6, soi % 3 == 0isTruebecause6 % 3 == 0.- The
breakstatement is executed, and the loop stops.
Conclusion:
The output is 2 4.
Answer:
(B) 2 4
Correct Answer: B) 2 4