...
EXP05-EX0: The increment and decrement operators (++)
and (--)
read a numeric variable, and then assign a new value to the variable. While these operators read and modify a value, they are well-understood and are an exception to this rule. This exception does not apply if a value modified an increment or decrement operator is subsequently read or written.
EXP05-EX1: The logical operators conditional-or ||
and conditional-and &&
operators have well-understood short-circuit semantics. Writes followed by subsequent writes or reads does not violate this rule if they occur in different subexpressions operands of ||
or &&
. Consider the following code example:
Code Block | ||
---|---|---|
| ||
public void exampleMethod(InputStream in) { int i; // Process chars until '' found while ((i = in.read()) != -1 && i != '\'' && (i = in.read()) != -1 && i != '\'') { // ... } } |
The This rule is not violated by the controlling expression of the while loop does not violate this rule because the subexpressions on either side of the because the rule is not violated by any operand to the conditional-and &&
operators do not violate it. The first and third subexpressions have exactly subexpressions (i = in.read()) != -1
have one assignment and one side effect (the reading of a character from in
).
...