Okay, for starters, if you plan to execute multiple statements following an if or else, you need to surround said statements in braces.
E.g.
Code:
if (someCondition) {
doW();
doX();
} else {
doY();
doZ();
}
Your version looks more like this:
Code:
if (someCondition)
doW();
doX();
else
doY();
doZ();
In this case, doX() will happen regardless of the condition. If braces are omitted, only the statement immediately following the condition is conditional. Wrapping statements in braces makes the whole block conditional.
In fact, this latter example would not compile at all, since the compiler would see that the "else" was detached from the "if" (separated by the non-conditional doX() method).
Bookmarks