This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Increment operator

ahsan mir
Ranch Hand
Posts: 42
hello,
i dont get why the output is x=8 , y=2 and NOT x=4 , y=1.
A step by step solution would be appreciated

***************************************************************************

public class Foozit {

public static void main(String[] args) {

Integer x=0;
Integer y=0;
for(Short z=0;z<5;z++)
if((++x >2)||(++y > 2))
x++;//in the second iteration x starts at 1 and not 2?!
System.out.print(x + " " +y);
}

}

***************************************************************************

ahsan mir
Ranch Hand
Posts: 42
Got it!
the x++ only comes into play once x value reaches 3 in the third iteration.

wise owen
Ranch Hand
Posts: 2023
the x++ only comes into play when x value greater than 2 which is from the third iteration to end.