Hi guys I find myself going back to the basics day by day. if the postfix operator precedence is much higher than the equality (==) operator, then in the following code: int i = 0; while( i++ == 0 ) System.out.print(i); System.out.print(i); shouldn't the expression be treated as follows? while( (i++) == 0 ) System.out.print(i) ?? BUT the the value is first compared and then incremented. The output is therefore '12'.
A postfix operator will return the original value first before incrementing. In while( i++ == 0 ), you have ( 0 == 0) After this boolean statement executes, i is now equal to 1 and System.out.print(1). The while condition is now false so the next stament is executed, which is System.out.print(2); [ August 22, 2002: Message edited by: Anthony Villanueva ]
Thanks Zarina & Anthony. I understand the reason for the output. But My question was regarding the operator precedence. The precedence of the postfix operator is higher than the equality operator. In this case, shouldn't the value be incremented before comparison? according to the precedence table? Thanks.