Ask Question
27 December, 04:48

Nested if-else structures can contain many blocks of code. How many of those blocks of code might be executed?

+1
Answers (1)
  1. 27 December, 07:38
    0
    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"<
    else

    { cout<<"number is greater than 1"<
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Nested if-else structures can contain many blocks of code. How many of those blocks of code might be executed? ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers