As I have learned that if the condition is false, statement should not be executed even once.
But when I compiled it, it gave me a warning of unreachable code - cout<<n;
and after ignoring the warning i executed the program, and found that the statement was executed once. I am unable to understand why was it executed.
That's exactly right. My compiler (gcc 4.7.1) complains about null statement for loops, because they can be optimised to whatever the conditional evaluates to at the end of the loop.
Nothing happens with my compiler, as expected. The fact is, that loop will never execute under any circumstance, and therefore, will be removed, along with any statements that are associated with it.
Either your object files are out-of-date, or, your compiler was unable to optimise the loop away, and was forced to execute the loop at least once. Or, maybe, your compiler is old, and non-compliant with the standard, which could mean the compiler tests the condition of the loop after at least 1 iteration.
is exactly the same as a=10; so that is why my compiler issues an error.
I still wonder why people ask such pedantic questions (the OP's one I mean), with code that is pointless. There has been 1 reply from the OP at the start - is he trolling?