Loops in Java


A statement or set of statements that is executed repeatedly is known as loop. The structure that repeats a statement is known as repetitive, iterative, or looping construct. Loops are basically used for two purposes.

To execute a statement or number of statements for a specified number of times for example, a user may display his name on screen 10 times.

To use a sequence of values e.g. a user may display a set of natural numbers from 1 to 10.

In Java there are three types of loops:

  1. While loop
  2. For loop
  3. Do-while loop