while, do-while, for, loop iteration statements in Java

while statement: while statement checks for a condition, and when it’s true it executes the statement.


while(condition) {

body of while loop;


do-while loop: In a do-while loop , the execution of the statement happens first, then a particular condition is checked. When the condition is true, loop is repeated, otherwise, terminated.


do {

body of do-while loop;

} while (condition);

for loop: for loop works in 4 steps: initialization, checking condition, if condition is true then execution and finally iteration (increment or decrement). This process is repeated until a false is encountered for the condition.


for(initialization; condition; iteration) {

body of for loop;


Leave a Reply