Hello to all, my first post, but it seems like maybe it's a skosh beyond "beginner" so I'm dropping it in here...
Background, I just got Head First Java (2nd ed.) and was looking over the "sharpen your pencil" on pg. 13.
I thought I'd get a little tricky, and the first time I keyed in the code I used "x += x;" (line 7, which was "x = x + 1;" in the book) and was interested and surprised to find that the output skipped the final "Do" (output was only DooBeeDooBee) until I set the if statement to "x == 4".
Maybe it's only because it's getting late that I'm missing the cause, but from how I'm looking at this, I don't see how x ever got to 4... if it get's incremented to 3, then the while loop should end and not increment x again, yet somehow x gets to 4...
Notice how the behavior was described by those that answered here. I'm just pointing this out so you can use a similar technique in the future. Usually a table of some kind that contains the values of variables can be very helpful in understanding what your code is doing. Pull out a pencil and piece of paper to do this. Sure it may seem antiquated in this electronic age, but it sure helps in many situations. As you fill out the table, mentally execute each line of code and calculate what the values should be for each variable. Of course, this means you need to understand what each line actually does. But that's part of the learning process.
Welcome to the Ranch, Curtis!
p.s. If you are only on page 13 in HFJ, then you should probably post future questions to the beginner's forum.