Chapter 4. Discovering Loops and Methods

In this chapter, we will learn how to repeatedly execute portions of our code in a controlled and precise way by looking at different types of loops in Java. These include while loops, do-while loops, and for loops. We will learn about the best occasions to use the different types of loops.

Then we will briefly cover the topic of random numbers. We will also see how the Java Random class can be used. This will obviously be of great help in enhancing our math game.

Next, we will look at methods. They allow us to compartmentalize our code into more manageable blocks. We will then see how to share data between methods and divide programming tasks to simplify problems.

We will then use all that we have learned ...

Get Android Game Programming: A Developer’s Guide 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.