You can use loops to re-run a particular code segment until it satisfy a certain condition.
Basically there are 3 basic types of loops in Java.
- While loop
- For loop
- Do-While loop
For example :
x++ => increment the value of x by one
The printing statement will run 11 times until the condition becomes false.
The code will execute until the condition becomes False.
This loop can be used to run a loop at least one times.
Likewise you can use the loops as you need to run over the same set of lines again and again.
Enhanced for loop will be discussed later.