The word nested itself signifies one within another. Nested if-else statement also signifies the same, an entire if-else structure can be written the body of the if statement or the else statement or within both individually.
Syntax of nested if-else statement is as follows:
if(condition 1)
{
if(condition 2)
{
statement 1;
statement 2;
--------------
statement n;
}
else
{
statement 1;
statement 2;
--------------
statement n;
}
}
else
{
if(condition 3)
{
statement 1;
statement 2;
--------------
statement n;
}
else
{
statement 1;
statement 2;
--------------
statement n;
}
}
In the above syntax two if-else structures are used individually within if and else statements respectively.
Syntax of nested if-else statement is as follows:
if(condition 1)
{
if(condition 2)
{
statement 1;
statement 2;
--------------
statement n;
}
else
{
statement 1;
statement 2;
--------------
statement n;
}
}
else
{
if(condition 3)
{
statement 1;
statement 2;
--------------
statement n;
}
else
{
statement 1;
statement 2;
--------------
statement n;
}
}
In the above syntax two if-else structures are used individually within if and else statements respectively.
No comments:
Post a Comment
Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...