The "nested if" statement
When an "if statement"is used within another "if statement", it is called the" nested if statement". The nested if statement is used for multi way decision-making.
if (condition-1)
{
if (condition-2)
{
statement-2;
}
statement-3;
}
In the above syntax, if the condition-1 is true then the controls shifts to the next "if statement" and the condition-2 is tested.
If the condition-2 is true then statement-2 is executed. The control will then pass to statement-3 and this statement will be executed.
If condition-2 is false, then statement-2 is skipped and the control shifts to statement-3 and it will be executed.
The "if statement" for testing condition-2 is within another "if statement". This "if statement" is called the "nested if statement".