... by Bit in Java Tutorial August 29, 2018

What Is A Loop?

In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.

Types Of Loops In Java?

While Loop - A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

//execute code

For Loop - A for loop provides a concise way of writing the loop structure. Unlike a while loop, a for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.

for (int i = 0; i < 10; i++){
    //execute code 

Do while - A do while loop is similar to while loop with only difference that it checks for condition after executing the statements. Therefore, the loop will at least loop once.

//execute code 
} while (true);

Comments (0)

Search Here