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 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.