lundi 5 octobre 2015

How to prove the order of execution of a nested else statement?

Please note that it's not a question on how else binds and how the scope stretches. Also, please note, that it's not a question on if we should or shouldn't use curly braces.

Regard the following nested conditional statement.

if(alpha)
  if(beta)
    AlphaAndBeta();
  else
    AlphaNotBeta();

Personally, even if I'm a big believer of removing any redundant parenthesis, I'd suggest usage of curly braces in this case to make it abundantly clear that the else statement is a part of the inner condition, which can be tricky to see, especially if some smart-donkey starts horsing around with the indentation like so.

if(alpha)
  if(beta)
    AlphaAndBeta();
else
  AlphaNotBeta();

However, I'd like to have a handy reference to where the behavior is described. I've looked at the language definition on MSDN but haven't found the exact spot. It needs to be super-ultra-clearly stated how the else bind to its if (and doesn't necessarily have to be MS's official site).

Where can I find the page, please?

Aucun commentaire:

Enregistrer un commentaire