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

Note that this is not a question of how else the anchors and how the region is stretched. Also, note that this is not a question of whether we should or should not use curly braces.

Note the following nested conditional statement.

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

Personally, even if I am a big proponent of removing extra parentheses, I would suggest using curly braces in this case to make it very clear that the else statement is part of an internal strong> state, which may seem complicated, especially if some kind of smart donkey starts throw in such an indent.

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

. MSDN, . -- , else if ( MS).

, ?

+4
2

MSDN:

then-statement else-statement , if if. if else , .

+6

#, 8.7.1 - if:

else if, . , if

if (x) if (y) F(); else G();

if (x) {
   if (y) {
      F();
   }
   else {
      G();
   }
}
+7

Source: https://habr.com/ru/post/1610250/


All Articles