+ 2
What is nested if?
Please give examples to understand.
2 Answers
+ 3
a nested if is an if statement inside another if statement. For example
if(age>=18){
if(income>5000) /* this is a nested if because is
inside another if */
{
// some code
}
else. // this else statement is also nested
{
// some code
}
}
+ 1
As bogdan said. Note that you should always place the curly braces because constructs like this are hazzarduous:
if ( boolean expression )
if ( boolean expression )
if ( ... )
else// caution: to which if does it belong?