STRUCTURED PROGRAMMING

Java, like C++ is a structured language.  There are three types of structures.
1.    Sequence.  The statements are executed one after another.
2.    Selection.  A logical true or false determines which path is followed.  In Java, there are three types of selection structures.
    a.    The if selection structure either performs (selects) an action if a condition is true or skips the action if the condition is    false.
    b.    The if/else selection structure performs an action if the condition is true and performs a different action if the condition is false.
    c.    The switch selection structure performs one of many different actions, depending on the value of an expression.
3.    Repetition.  A certain portion of the code is performed repeatedly.  This is also known as loping or iteration.  There are three types of repetition structures.
    a.   In the while structure, a loop is performed repeatedly as long as the condition is true.  The loop is broken when the condition becomes false.  The test for the condition is made at the beginning of the loop.  The loop will be performed zero times if the condition is initially false.   The condition has to be changed in the loop to eventually make it false.  Otherwise we will get an endless loop.  The number of times that the loop is to be executed need not be known.
    b.    In the do/while structure, a loop is performed repeatedly as long as the condition is true.  The loop is broken when the condition becomes false. But in this case, the condition is tested at the end of the loop.  So the loop will be performed at least once, even if the condition is initially false.  The condition has to be changed in the loop to eventually make it false.  Otherwise we will get an endless loop.  The number of times that the loop is to be executed need not be known.
    c.    In the for repetition structure there is a counter.  The initial value, the end value, and the increment value is initially specified.  In this case, the number of iterations must be known, but it is not possible to be trapped in an endless loop.

For more details:     Details of loop structures