Chapter 5
Going Around in Circles (Or, Using Loops)
IN THIS CHAPTER
The thrill of while loops
The rapture of infinite loops
The splendor of do loops
The joy of validating input
The wonder of for loops
The ecstasy of nested loops
So far, all the programs in this book have started, run quickly through their main
method, and then ended. If Dorothy from The Wizard of Oz were using these programs, she’d probably say, “My, programs come and go quickly around here!”
In this chapter, you find out how to write programs that don’t come and go so quickly. They hang around by using loops, which let them execute the same statements more than once.
Loops are the key to writing one of the most common types of programs: programs that get input from the user, do something with it, get more input from the user and do something with that, and keep going this way until the user has had enough.
Put another ...
Get Java All-in-One For Dummies, 5th 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.