All lessons

Loops

8 min · Java

Repeat work without writing it out a hundred times.

Java · Loops0/5 cleared

Enemy 1 of 5

A loop repeats a block of code so you don't have to write it out by hand over and over. A for loop packs three parts into its parentheses, separated by semicolons: a starting point, a condition to keep going, and a step to run after each pass.

This counts i from 0 while i is less than 3, adding 1 each time (i++) — so the loop body runs exactly three times, printing 0, 1, and 2. Java checks the condition before every pass through the loop, so the moment it's false, the loop stops immediately without running one extra time.

You
Invisible Heisenbug
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.

Stuck? Ask Rena

Your AI tutor that gives assistance.

Asking Rena in lessons is on Ultimate.