Conditional (If-Else) Statements

The conditional statement in Apex works similarly to Java.

The else portion is always optional, and always groups with the closest if. For example:

is equivalent to:

Repeated else if statements are also allowed. For example: