Loops are classified into two types according to their type of iteration, i.e., fixed iteration and variable iteration. In fixed iteration, the statements are repeated for a fixed number of times. In variable iteration, the loop can be applied to a program where number of iterations is not fixed. A loop consists of following parts: initialisation expression, test expression and update expression(s).
The ‘for’ is a shorthand, which combines initialisation, condition and increment in one statement. If a loop does not contain any statement in its loop-body, it is said to be an empty loop. It contains null statement. A loop placed inside another loop of the same type is called the nested loop. A variable scope defines the visibility of variable within the program. The ‘do-while’ is used to repeatedly execute the statements till the specified condition remains true. The ‘do-while’ loop is an exit-controlled loop in which the loop body is executed first and the condition is checked at the end. A loop placed inside another loop of the same type is called the nested loop.
The ‘while’ loop used within another while loop is called ‘nested while’ loop. Jump statements transfer the control of the program from one position to another conditionally or unconditionally. Java has three jump statements: break, continue and return. The break statement skips the rest of the loop and jumps over to the statement following the loop. The continue statement is used to move control to the start of the next repetition.