1- the code enters label1 and h is incremented. Now its value is 1; 2- the code enters label2 and i is incremented to 1; 3- k = h + i + j = 2. The statement is executed inside the switch block, which causes the code to exit the switch block; 4- The statement is executed, incrementing j to 1; 5- the do-while loop executes again, incrementing i again to 2; 6- k = h + i + j = 1 + 2 + 1 = 4. The statement is executed inside the switch block. This means that the do-while loop will continue. But before it moves to the next iteration, the while(++j < 5) is executed again to check whether the loop should be executed again or not. This causes j to be incremented to 2; 7- the do-while loop executes again, incrementing i to 3; 8- k = h + i + j = 1 + 3 + 2 = 6. The will execute and cause the end of the for loop. The code moves to the System.out.println statement printing the values 1, 3 and 2 for h, i and j.
When you face code samples like this, try writing down the variables and its respective values to help you keep track of what is going on.
Hope this helps, Stefan [ January 22, 2005: Message edited by: Stefan Guilhen ]