Chapter 6. Repeating Blocks of Code with Loops

In this brief chapter, we will learn about Java loops that enable us to repeat sections of our code in a controlled manner. Loops in Java take a few different forms and we will learn how to use them all and throughout the rest of the book we will put each of them to good use.

In this chapter, we will look at:

  • while loops
  • do-while loops
  • for loops
  • How to draw the grid lines of the Sub' Hunter game (using loops)

This is the second to last chapter before we have completed the first game and move on to a more advanced project.

Decisions, decisions

Our Java code will constantly be making decisions. For example, we might need to know if the player has been hit or if they have a certain number of power-ups. We need ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.