Please explain this

i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2

so, i is initially set to 2.
and within the loop, it is increased by 2 every loop. and the loop is set to break if the condition "i%3==0ā€™. it means if the value of i is ever a multiple of 3, the loop will break.
so, at first , i =2, within the loop, if condition is not satisfied, then prints ā€œiā€ which is 2, then i is increased by 2 and becomes 4.
again the same process happens, condition is not satisfies, i is printed, and i is increased to 6.
on the next loop, the condition is satisfied and the loop breaks. so, the function prints 2 4 in the end.

3 Likes