Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Loop Types

ETL LABS PVT LTD – JAVA PROGRAMMING 91


Types of Loops

Type 1 Type 2 Type 3

while loop do...while loop for loop

ETL LABS PVT LTD – JAVA PROGRAMMING 92


while Loop
The while loop executes a block of code as long
as the specified condition is true.

2 Syntax
while (condition is true)
{
code to be executed;
}

ETL LABS PVT LTD – JAVA PROGRAMMING 93


do...while Loop
The do...while loop will always execute the
block of code once, it will then check the
condition, and repeat the loop while the
specified condition is true.
3
Syntax
do
{
code to be executed;
}
while (condition is true);

ETL LABS PVT LTD – JAVA PROGRAMMING 94


for Loop
The for loop is used when you know in
advance how many times the script should run.

Syntax
4 for (statement 1; statement 2;
statement 3)
{
code to be executed;
}

ETL LABS PVT LTD – JAVA PROGRAMMING 95

You might also like