The loop body will run exactly zero times. On the first iteration, x != 0
will be false.
In the general case of a for
loop:
for (<initializations>; <condition>; <post> ) {
<body>
}
the execution sequence is:
<initializations>
if <condition> then end
<body>
<post>
go to 2.
(A) will the loop run 4 billion times because x will start at 0 then approach max value (2^31-1)
Nope. The arithmetic is wrong. 2^31-1 is not 4 billion. It is a bit over 2 billion.
(B) will the loop run 2 billion times because x will approach max value then an error will appear.
Nope. Integer overflow in Java doesn't raise an error / exception.
(C) will it run forever because x will approach infinity
Nope. It wouldn't approach infinity. An int
value cannot be larger than Integer.MAX_VALUE