Branching Statements
We have already examined one branching statement: break. The break statement when executed will exit the current loop.
Another useful branching statement is continue. The continue statement goes immediately back to the conditional statement of the loop and checks to see if it is still met
Pre and Post Increments
In While and Do-While statements there is one very commonly used line of code: x = x + 1. Java has two shortcuts for this: the post-increment x++ and the pre-increment ++x.
When used on their own line of code the increments appear to do the same thing
But when used inside of a method call, the increments behave differently:
Which Loop should I use?
You now have three loops to choose from. The question is, which one is best to use?
For Loop:
A counted loop
Great choice if you know exactly how many loops to perform, or if that number can be supplied by the user
Do-While Loop:
The loop always runs at least once
Great choice when asking a question, the answer to which will determine if you loop again
While Loop:
A good multi-use loop for dealing with: o User input o Numbers o Strings