Important MCQ

Sum of the digits of 123 using while is

Q.Sum of the digits of 123 using while is

A) 12
B) 3
C) 123
D) 6
Correct Answer:
Option D
Detailed Explanation:
D) 6 is correct. A while loop checks its condition before each iteration, so it may run zero times. The loop body must update state when needed to avoid an unintended infinite loop.