Home » java » Looping statement

Looping statement

Looping is also known as Iteration statement
Iteration statement are used to repeat a set of statement.

Following statement are used for iteration.
1. For statement
2. While statement
3. Do while statement

1.For statement

Syntax:

Example

Output

In for statement first loop variable is initialized then condition is checked if condition is true body of loop is executed after that variable is updated
Again condition is cheeked condition satisfied body of loop is executed and variable updated this process is continue until condition is false. Variable initialization is done only once.

While statement

Syntax

In while statement only condition is checked if condition is true then the body of loop is executed loop variable initialization should be before the while statement. Variable updating is part of body of loop.


Example

Output

do while statement

Syntax

In do loop condition is cheeked at last. First time body of loop is excuted without checking the condition after that if condition specified in while is true then body of loop is executed until condition is false.
Example

Result

If condition is false then also do while statement is executed once.
Example

Result

Here condition in do while is false then also body of loop is executed once.

Managed by MochaHost - Fast & Easy WordPress Hosting