What is a Loop?
A loop is used for repetitive execution of a particular block simultaneously until the given condition became false.
It is a controlled statement which controls the flow of the program execution. It uses a conditional statement in order to decide at what extent a particular block should be repeated. A loop is a basic construct in Java.
There are three types of loops:
1) While Loop
2) Do While Loop
3) For Loop
It can be controlled in two ways: Entry controlled loop and Exit Controlled loop.
Entry Controlled Loop
An entry controlled loop is a type of loop in which the condition is checked first and then after the loop body executed.
If the test condition is true, the loop body would be executed otherwise, the loop would be terminated.
Exit Controlled Loop
Oppose to Entry controlled loop, it is a loop in which condition is checked after the execution of the loop body.
The loop body would be executed at least once, no matter if the test condition is true or false.
Difference between entry controlled loop and exit controlled loop
|Entry Controlled Loop||Exit Controlled Loop|
|A loop in which the given condition is checked first, before entering into the loop body||A loop in which the loop body is executed first and then after the given condition checked.|
|The loop body would be executed if and only if the given condition is true||The loop body would be executed at least once, regardless what the condition is|
|For Loop and While Loop are examples of this type of loop||Do While Loop is an example of exit controlled loop|