Incautious use of semicolons
suggest changeBe careful with semicolons. The following example
if (x > a);
a = x;
actually means:
if (x > a) {}
a = x;
which means x is assigned to a in any case, which might not be what you wanted originally.
Sometimes, a missing semicolon causes a problem that is easy to overlook:
if (i < 0)
return
day = date[0];
hour = date[1];
minute = date[2];
The semicolon after return is missing, so the statement returns the value assigned to day, which is date[0].
One technique to avoid this and similar problems is to always use braces on multi-line conditionals and loops. For example:
if (x > a) {
a = x;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents