If Else in Fortress
Branching with if
and else
in Java is straightforward.
To run the program, compile and execute it using javac
and java
:
Note that in Java, you need parentheses around conditions, and the braces are required for multi-line blocks but optional for single-line blocks.
Java does have a ternary operator (?:
), which can be used for simple conditional expressions. For example:
This is equivalent to:
The ternary operator can be useful for simple conditions, but for more complex logic, full if
-else
statements are often more readable.