Advertisements
Advertisements
प्रश्न
Give the output of the following program segment and mention how many times the loop is executed.
int K= 1;
do
{K+=2;
System. out.println (K);
} while (K<=6);
दीर्घउत्तर
Advertisements
उत्तर
3
5
7
Number of times the loop is executed
The loop is executed 3 times.
- Initialisation: K starts at 1.
- 1st Iteration: K becomes 1 + 2 = 3. It prints 3. The condition (3 ≤ 6) is true, so the loop continues.
- 2nd Iteration: K becomes 3 + 2 = 5. It prints 5. The condition (5 ≤ 6 ) is true, so the loop continues.
- 3rd Iteration: K becomes 5 + 2 = 7. It prints 7. The condition (7 ≤ 6) is false, so the loop terminates.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Official Board Paper
