Computer Science, asked by Kanchhi4473, 1 year ago

What is the problem of dangling else . what does it arise

Answers

Answered by niri1607
0

Well first of all, let's discuss about the most used if statements:

1. if

2. if then else

3. nested if then else

now lets imagine a scenario;

Statement: if (bool) if (bool2) a; else b;

now the above statement could be visualized like such:

case 1:

if (bool){

 if(bool2){

     a;

  else

    b;

}

}

case 2:

if(bool){

 if(bool2){

       a;

  }

}

else{

     b;

 }

In which both are true for the above said statement. Now this arises a dangling else condition.

In case 1, b is printed if bool is true and bool2 is false.

In case 2, however, b is printed if both bool and bool2 are false.

This arises an Ambiguity on selecting the case suitable for the said statement.

Similar questions