+ 2

What is nested if?

Please give examples to understand.

4th Sep 2016, 5:19 AM
Kabeer
Kabeer - avatar
2 Antworten
+ 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 } }
4th Sep 2016, 9:56 AM
bogdan
bogdan - avatar
+ 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?
4th Sep 2016, 11:34 PM
René Schindhelm
René Schindhelm - avatar