निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
i = 2
while True:
if i%3 == 0:
break
print(i,end=" " )
i += 2
A)
B)
C)
D)
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 == 0
isFalse
because2 % 3 == 2
.print(i, end=" ")
prints2
.i += 2
makesi = 4
.
-
Second iteration:
i = 4
, soi % 3 == 0
is stillFalse
because4 % 3 == 1
.print(i, end=" ")
prints4
.i += 2
makesi = 6
.
-
Third iteration:
i = 6
, soi % 3 == 0
isTrue
because6 % 3 == 0
.- The
break
statement is executed, and the loop stops.
Conclusion:
The output is 2 4
.
Answer:
(B) 2 4