C H A P T E R  5

Control Flow, Looping, and Branching

Control flow, looping, and branching are fundamental concepts in all programming. Control flow consists of running different code under different conditions. Looping consists of running the same code (though often with different values or different objects each time) until some condition has been met. Branching consists of doing something else when some condition has been detected. The thread that ties them all together is detecting conditions.

Control Flow

Java offers two constructs for controlling the flow of a program.

  • if and if-else
  • switch

images Note try-catch blocks offer a form of control ...

Get Java 7 for Absolute Beginners 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.