if-else

The if-else statement is probably the most basic way to control program flow. The else is optional, so you can use if in two forms:

if(Boolean-expression)
statement

or

if(Boolean-expression)
statement
else
statement

The conditional must produce a boolean result. The statement is either a simple statement terminated by a semicolon, or a compound statement, which is a group of simple statements enclosed in braces. Any time the word statement is used, it always implies that the statement can be simple or compound.

As an example of if-else, here is a test( ) method that will tell you whether a guess is above, below, or equivalent to a target number: