Formatting and scoping errors
if(mycondition);
{
// Why this code is always executed ???
}
There's a superfluous ; after the if() statement.
if(mycondition)
statement1();
statement2(); // Why this code is always executed ???
The code is equivalent to
if(mycondition) {
statement1();
}
statement2();
statement2(); is outside the scope of the conditional block. Add {} to group statements.
if (mycondition)
if (mycondition2)
statement1();
else
statement2();
The code is equivalent to
if(mycondition) {
if (mycondition2)
statement1();
else
statement2();
}
else apply on previous if. Add {}:
if (mycondition) {
if (mycondition2)
statement1();
}
else
statement2();
The same applies for any wrongly placed ; in loop statements like
for(int x = 0;x < 5;++x);
// ^
{
// statements executed only once
}
or
while(x < 5);
// ^
{
// statements executed only once
}