Title: Key Concept - If Statement
Course: CPS 189: Java Certification - Review, Practice & Prepare (Development) > Section: (OLDstyle) Learning Modules

The if statement supports decision-making and has unlimited variations:

Test whether to execute a block or not.

if (<condition>)
{
<block>
}

Test whether to execute one of two blocks.

if (<condition>)
{
<block-1>
}
else
{
<block-2>
}

Test whether to execute one of several blocks or not (statement ends with else if clause).

if (<condition-1>)
{
<block-1>
}
else if (<condition-2>)
{
<block-2>
}
...
else if (<condition-n>)
{
<block-n>
}

Test whether to execute one of several blocks (statement ends with else clause).

if (<condition-1>)
{
<block-1>
}
else if (<condition-2>)
{
<block-2>
}
...
else if (<condition-n>)
{
<block-n>
}
else
{
<block-n+>
}

For more information about the if statement clause:

- Click this link to view Oracles's documentation : The if-then and if-then-else statements.
- Level 1 Study Materials: Unit 2