2.5 Conditional Statements or Case Distinctions
Control structures are used in a programming language to execute specific program parts under certain conditions. Java provides the if and if- else statements as well as the switch statement for executing various parts of the program. Besides branching, loops are used to execute program parts multiple times. The significant part in the phrase “control structures” is the word “structure” because the structure should be obvious by just looking at it. Without loops and “high-level” control structures, only if/thens and jumps, the logic of the program was not obvious, and the result was called spaghetti code. Although a general jump via goto isn’t possible in Java, the language still has a special ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access