Multiple choice technology programming languages

What is the value of variable z when the following program segment ends? int z; for(z=0; z<50; z++) {}

  1. 51

  2. 49

  3. 0

  4. 50

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

The loop initializes z=0 and continues incrementing while z<50. The loop exits when z becomes 50, which fails the condition. At exit, z equals 50. The loop body is empty, so only the increment happens each iteration.