Multiple choice technology programming languages

What is the value of k after the following code fragment? int k = 0; int n = 12 while (k < n) { k = k + 1; }

  1. 0

  2. 11

  3. 12

  4. -1

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

The loop increments k from 0 until k equals n (12). The loop condition is k < n, so it executes 12 times. When k becomes 12, the condition fails and k remains 12.