Multiple choice

What is the value of 'number' after the following code fragment execution? int number = 0; int number2 = 12 while (number < number2) { number = number + 1; }

  1. 5

  2. 12

  3. 21

  4. 13

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

The while loop continues as long as number < number2 (12). Starting from 0, number increments by 1 each iteration. After 11 iterations, number becomes 11, which is still < 12, so one more iteration occurs, setting number to 12. Now 12 < 12 is false, so the loop exits. Final value is 12.