How many times will the following loop iterate?
int x = 10;
while (x > 0)
{
System.out.println(x);
x--;
}
a) 0 times
b) 1 time
c) 9 times
d) 10 times
e) 11 times
Answer: d. Explanation: Since the condition is tested before the loop body executes, the loop will not execute once x == 0. So, the loop iterates for x = 10, x = 9, …, x = 1, or 10 times.