Search code examples
if-statementadaconditional-compilation

What advantage does the end if statement in Ada provide over other languages


Most other programming languages don't have an end if statement required at the end of conditional statements.

if boolean_expression then statement else statement

What advantage does including an end if provide Ada that other languages don't have?

if boolean_expression then statement else statement end if

I think it has something to do with branch prediction if the condition is true (skips the else portion of the code), but I'm not sure.


Solution

  • Consider a nested if, like this: if boolean_expression then if another_boolean_expression then statement else statement

    Now, to which if statement does the else part belong?

    end if resolves the issue (indented for clarity):

    if boolean_expression then 
       if another_boolean_expression then
          statement 
       end if;
    else
      statement 
    end if;
    

    or:

    if boolean_expression then 
       if another_boolean_expression then
          statement
       else
          statement
       end if;
    end if;