Answer:
A nested if else structure is defined as using one if-else inside another one. It is used when you want a take a decision by checking several conditions. Nested if can contain many block of codes with each block executing if the certain condition is met for each of that block.
The number of blocks of code, that might be executed depends on the condition that is intended to be met, in order to take a certain decision based on that condition. Let suppose if the desired condition is met in the very first block of code then only one block of code is executed. For example consider the following code:
if(number<5)
{ if(number==1) {
cout<<"number is 1"<<number;
}
else
{ cout<<"number is greater than 1"<<number; }
}
else
{ cout<<"number is greater than 5";}
Suppose the number entered is 1. So the first nested if condition is true and number is 1 will be displayed. So none of the else blocks has to be executed.
Number of code blocks that might be executed also relies on the number of block present in the code.
The execution also depends on the number of blocks that are true or false. If you want to execute a block for true condition, nested if else looks through every block until the block with the true desired condition is reached but if you want false condition to be checked to display the block of code when condition gets false then it will look through all the blocks until it gets the block with that false part.
For example consider the following code:
if ( number > 0)
{ cout << "its a positive number: " << number; }
else if (number < 0)
{ cout<<"its a negative integer: " << number; }
else {
cout << "its a 0"; }
Suppose the number is 0 and the program has to sequentially checks for each condition. It will check number>0 which is not what we need, then it will check else if statement for number<0 which is again not desired and finally it will display the block "its a 0" which matches the desired condition.