Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question: 9 what is the last thing printed by the following program? va…

Question

question: 9
what is the last thing printed by the following program?
var start = 30;
var stop = 10;
for(var i = start; i >= stop; i-=5){
if(i % 2 == 0){
println(i * 2);
} else {
println(i);
}
}
10
20
30
60

Explanation:

Step1: Analyze the for loop

The for loop starts with i = 30 (since start = 30), and continues as long as i >= stop (where stop = 10), with i decrementing by 5 each iteration.

Step2: Check each iteration

  • When i = 30: 30 % 2 = 0, so print 30 * 2 = 60.
  • When i = 25: 25 % 2 != 0, so print 25.
  • When i = 20: 20 % 2 = 0, so print 20 * 2 = 40.
  • When i = 15: 15 % 2 != 0, so print 15.
  • When i = 10: 10 % 2 = 0, so print 10 * 2 = 20.

Answer:

20