...
EXP05-EX1: The logical operators ||
and &&
have well-understood short-circuit semantics, so expressions involving these operators writes followed by subsequent wrtes or reads do not violate this rule . Consider if they occur in different subexpressions of ||
or &&
. Consider the following code example:
Code Block | ||
---|---|---|
| ||
public void exampleMethod(InputStream in) { int i; // SkipProcess onechars char,until process'' nextfound while ((i = in.read()) != -1 && i != '\'' && (i = in.read()) != -1 && i != '\'') { // ... } } |
Although the conditional expression appears to violate this rule, this code is compliant because the subexpressions on either side of the &&
operator operators do not violate it. Each subexpression has The first and third subexpressions have exactly one assignment and one side effect (the reading of a character from in
).
...