Logical OR (||) expresses alternative conditions: a combined condition succeeds when either operand is true. Confusing it with logical AND (&&) can make validation or filtering conditions impossible to satisfy. section 2.8
Avoid the common failure modes:
- Use || when rejecting values outside a range; a value cannot be both below the lower bound and above the upper bound. section 2.8
- When negating a disjunction, preserve De Morgan’s law: !(a || b) becomes !a && !b, not !a || !b. section 2.8
- Prefer parentheses around compound conditions so the intended grouping remains visible. section 2.8
Correcting a printable-character check
The faulty condition uses && between mutually exclusive bounds, so it never rejects a character outside the printable range. Replace that inner operator with || while retaining the exclusions for tab and newline.
void processLine(String line) {
// Ignore comments
if (!line.startsWith("#") || !line.startsWith("//")) {
processContentLine(line);
}
}
Inspect the deceptive negation that lets every line reach content processing instead of ignoring comment lines. section 2.8





