Looping is a core concept in computer science. If you need to repeat a task multiple times, you use a loop. In this short tutorial, we will learn exactly how a Java for loop works using a simple code example.

The Code Example

Here is a basic Java loop that prints a message five times:

for (int i = 0; i < 5; i++) {

System.out.println("The value of i is: " + i);