Originally posted by mithun gm:
...post-increment operator has higher precedence over less than operator.. so i feel, first the variable is incremented and then the comparision operator is evaluated...
The expression i++ is
evaluated prior to the < comparison being made. But the
postfix operator does not increment until
after returning a value.
In the words of the
Java Language Specification (
section 15.14.2), "The value of the postfix increment expression is the value of the variable before the new value is stored."
So as Biswa explained above: In this case, when i is 5, then i++ evaluates to 5 (which is used in the comparison test), and
then i is incremented to 6. So the test is passed, but within the loop itself, i is out of bounds.
[ March 19, 2006: Message edited by: marc weber ]