Answers already given are correct.
However i want to point out that it's not true that the loop has no body. You have to consider it once compiled. It becomes :
- Initialize i at 100
- Initialize j at 200
- Increment i
- Decrement j
- IF NOT(I < J) jump to 7
- Jump to 3
- Print and stuff
The loop in this case is from 3 to 6, and has a body (increment i decrement j) and a condition check at point 5.
To make it clearer, I will write another loop, functionally identical, but with a body :
while (true) {
i++;
j--;
if (!(i<j)) break;
}
Now this loop has a body, but probably the compiled version of this loop and the previous one are identical.
However, we could mean by "Empty body loop" a loop that has no side effects. For example, this loop :
for (int i = 0; i < 10000; i++);
This loop is "really" empty : no matter if you execute it or not, it doesn't give or take anything from the rest of the program (if not a delay).
So, we could define it "empty of any meaning" more than "empty of any body".
In this case, the JIT will notice it, and wipe it out.
In this sense, your loop could be :
for (int i = 100, j = 200; i < j; i++, j--);
Here, since "i" and "j" are declared "inside" the loop (doesn't exist outside it's scope), then this loop is meaningless, and will be wiped out.
Maybe this is what Herbert Shildt (that I admit I don't know) means?
Also see here Java: how much time does an empty loop use? about empty loops and JIT.