for example:
if(cond1)
if(cond2) DoCond2();
else DoCond3();
Will the else statement be considered as the else of the first if or the second if? Why? (is there an explanation from syntactic point of view?)
Is the answer also the same in the other C-based programming languages such as C and Java?
Note: this is not homework. I can easily test it, and use the curly brackets if I don’t like the default behaviour, but I’m curious as to the reason.
Edit Guys, apparently there was a very serious mistake in the original example. Please check again. I know, it’s embarrassing. Sorry.
As per MSDN
In nested if statements, the else clause belongs to the last if that does not have a corresponding else.
Also C and C++, conditions can be evaluated where a result of 0 is false and any other number is true. In C#, the condition must evaluate to a boolean value true/false
EDIT
As per the Edit its a nested if, so the inner one is evaluated when true and still the else is with the inner if