Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: in progress...

...

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. (Note that this rule can still be violated  This exception does not apply if a value is modified via ++ or -- and modified an increment or decrement operator is subsequently read or written.)

EXP05-EX1: The logical operators || and && have well-understood short-circuit semantics, so writes .  Writes followed by subsequent wrtes writes or reads do does not violate this rule if they occur in different subexpressions of || or &&.  Consider the following code example:

Code Block
bgColor#ccccff
public void exampleMethod(InputStream in) {
  int i;
  // Process chars until '' found
  while ((i = in.read()) != -1 && i != '\'' && 
         (i = in.read()) != -1 && i != '\'') {
    // ...
  }

}

Although the conditional expression appears to The controlling expression of the while loop does not violate this rule , this code is compliant because the subexpressions on either side of the && operators do not violate it. The first and third subexpressions have exactly one assignment and one side effect (the reading of a character from in).

...