5.2. Selection Statements
Java provides selection statements that allow the program to choose between alternative actions during execution. The choice is based on criteria specified in the selection statement. These selection statements are
simple if Statement
if-else Statement
switch Statement
Simple if Statement
The simple if statement has the following syntax:
if (<conditional expression>) <statement>
It is used to decide whether an action is to be performed or not, based on a condition. The condition is specified by <conditional expression> and the action to be performed is specified by <statement>.
The semantics of the simple if statement are straightforward. The <conditional expression> is evaluated first. If its value is true, then ...
Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second 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.