+ 1
What is nested if else statement? Thanks!
nested if else
2 Answers
+ 9
You can use one if or else if statement inside another if or else if statement(s):
if( boolean_expression 1)
{
/* Executes when the boolean expression 1 is true */
if(boolean_expression 2)
{
/* Executes when the boolean expression 2 is true */
}
}
+ 1
Generally speaking, you should be careful using with nested if statements. It increases what is called cyclomatic complexity, in other words you are creating several unique combinations of logic that take completely different paths in your code.
If you are properly indenting your code, usually if you see more than three indentions on a single line, you should see this as a sign that you should rethink your organization and refactor.