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