Give the output of the following program segment and mention how many times the loop is executed.

ICSE Class 10 Computer Applications PYQ · 2025 Improvement · Section A

2(vi)1 Mark · 2025 · Section A · 2025 Improvement

Give the output of the following program segment and mention how many times the loop is executed.

int k = 100; 
while (k>=10) 
{
    System.out.println(k); 
    k-=40; 
}
Show SolutionHide Solution↓
100
60
20

The loop is executed 3 times.

  • Initial value: k = 100 → printed, then reduced to 60.
  • Second iteration: k = 60 → printed, then reduced to 20.
  • Third iteration: k = 20 → printed, then reduced to -20.
  • Loop stops when k < 10.
← Previous questionNext question →

Browse the free Computer Applications sample bank