Looping Statement
Looping Statement
The initialization expression initializes the loop and is executed only once at the beginning
when the loop begins. The termination condition is evaluated in every loop and if it
evaluates to false, the loop is terminated. And lastly, increment/decrement expression is
executed after each iteration through the loop.
While Loop in Java:
The while statement or loop continually executes a block of statements while a particular
condition is true. The while statement continues testing the expression and executing its
block until the expression evaluates to false. The syntax to use while loop in java is given
below.
Do-while Loop in Java:
The difference between do-while and while is that do-while evaluates its expression at the
bottom of the loop instead of the top. Therefore, the statements within the do block are
always executed at least once.
Note that the do-while statement ends with a semicolon. The condition expression must be
a boolean expression. The syntax to use the do-while loop is given below.