A variant of that, if memory serves, is the deadly Java
if (condition); do_something();
See, you'll alwaysdo_something, because (condition) only applies to the statement immediately afterwards ... and that statement ends with the first semicolon. But semicolons are so common in Java it's very easy for the mind to overlook the fact that the first one there is spurious, and what you wanted to write was
if (condition) do_something();
(and as you point out, what you really wanted to write was if (condition) { do_something(); }
no subject
Date: 2008-07-19 12:44 am (UTC)if (condition);
do_something();
See, you'll always
do_something
, because(condition)
only applies to the statement immediately afterwards ... and that statement ends with the first semicolon. But semicolons are so common in Java it's very easy for the mind to overlook the fact that the first one there is spurious, and what you wanted to write wasif (condition)
do_something();
(and as you point out, what you really wanted to write was
if (condition) {
do_something();
}