Multiple choice technology programming languages

Consider the following program code: $x = 10; LOOP: while ($x < 15) { print ($x ); if ($x >= 14 && $x <= 20) { $x += 2; redo LOOP; } else { $x++; }} What is the result of executing this program code?

  1. The code will output the following: 11 12 13 14 15 16 17 18 19

  2. The code will output the following: 10 11 12 13 14 16 18 20 22

  3. The code will output the following: 10 11 12 13 14 16 18 20

  4. The code will output the following: 10 11 12 13 14 15 16 17 18 19 20

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The loop starts with $x = 10. For values 10 to 13, the else block increments $x by 1. When $x reaches 14, the if condition is met, $x is incremented by 2 to 16, and redo restarts the loop without re-evaluating the condition, printing 16, then 18, then 20.