5
Understanding Iteration
In Chapter 4, we learned about scope and conditional statements in Java. Scope determines the visibility of identifiers – in other words, where you can use them. Java uses block scope, which is defined by curly braces, {}. Scopes can be nested but not vice versa.
We discussed variations of the if statement. Each of these statements evaluates a boolean condition, resulting in true or false. If true, then that branch is executed and no other branch is evaluated. If false, then the next branch is evaluated. Unless an else clause is present, it is possible that no branch at all will be executed.
For complex if statements, Java supports the more elegant switch structure. We examined switch statements, with their fall-through ...
Get Learn Java with Projects 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.