O'Reilly logo

Minecraft Mods Programming Absolute Beginner’s Guide by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9. Repeat an Action with Loops

In This Chapter

Use the for loop

Use the while loop

Use the do-while loop

Exit a loop prematurely

Name a loop

A computer program can repeat a task with ease. Programs are ideally suited to do the same thing over and over because of loops. A loop is a statement or block that is repeated in a program. Some loops run a fixed number of times. Others run indefinitely.

There are three loop statements in Java: for, do, and while. Each can work like the others, but it’s beneficial to learn how all three operate. You often can simplify a loop section of a program by choosing the right statement.

for Loops

In your programming, you find many circumstances in which a loop is useful. You can use them to keep doing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required