O'Reilly logo

Java All-in-One For Dummies, 4th Edition by Doug Lowe

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

Chapter 5

Going Around in Circles (Or, Using Loops)

In This Chapter

arrow The thrill of while loops

arrow The rapture of infinite loops

arrow The splendor of do loops

arrow The joy of validating input

arrow The wonder of for loops

arrow 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 ...

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