Conditional Statement

> if Statement

Anif statementconsists of a boolean expression followed by one or more statements.

if (test expression/Condition)
{
   //statements to be executed if the condition is true
}

See Example

> if-else Statement

Anif statementcan be followed by an optionalelse statement, which executes when the Boolean expression is false.

if (test expression/Condition)
{
   //statements to be executed if the condition is true
}
else
{
    //statements to be executed if the condition is false
}

See Example

> nested if Statement

You can use aniforelse ifstatement inside anotheriforelse ifstatement(s).

if (test expression/Condition)
{
   //statements to be executed if the condition is true
}
else
 if (test expression/Condition)
{
    //statements to be executed if the condition is true
}
else if (test expression/Condition)
{
    //statements to be executed if the condition is true
}
else
{
    //statements to be executed if the condition is false
}

See Example

switch Statement

A switch statement allows a variable to be tested for equality against a list of values.

See Example