Part 11 – Java Loops
July 27, 2020 1 min read

Java loops are used to execute some set of functions repeatedly when some conditions become true. There are 3 types of loops.
- for loop
- while loop
- do-while loop
for loop
Java for loop is is a control flow statement that iterates a part of a program multiple times. If the no.of iteration is fixed, you can use the for loop.
In a for loop there are 3 main declerations.
- Initialization
- Condition
- Iteration

- From Initialization, it controls the variable. That means here we give the data type for the variable and assign a value to the variable.
- In condition part, we give a limit to the command that how much turns the loop should be run.
- In Iteration part you can see an increment. Iteration is compulsory to run the condition given in the loop. It will run until the condition becomes false.
Let’s see an example.

Here according to the condition given the command should run 10 times like below.

while loop
Java while loop is used to iterate a part of the program several times. If the no.of iteration is not fixed, you can use the while loop.

According to this example the command should run 10 times by incrementing 1 by 1 as given below.

do-while loop
Java while loop is also used to iterate a part of the program several times. If the no.of iteration is not fixed and you must have to execute the loop at least once, you can use the do-while loop.

Here it is saying do the printing command while it is running 10 times. See the output given below.

I think you all understood about the Java loops well. See you with the next article on topics Java Switch and Nested loop.
Thank you.


