Chapter 10. Control Flow

 

“Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to.”

 
 --Lewis Carroll, Alice in Wonderland

A program consisting only of a list of consecutive statements is immediately useful because the statements are executed in the order in which they're written. But the ability to control the order in which statements are executed—that is, to test conditions and execute different statements based on the results of the tests—adds enormous value to our programming toolkit. This chapter covers almost all the control flow statements that direct the order of execution. Exceptions and assertions are covered separately in Chapter 12.

Statements and Blocks

The two basic statements ...

Get THE Java™ Programming Language, Fourth Edition now with O’Reilly online learning.

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