Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
public class Scope {
  public static void main(String[] args) {
    for (int i = 0; i < 10; i++) { // containsContains declaration
      // Do operations
    }
  }
}

...

Detecting multiple for statements that use the same index variable is straightforward; it will produce false positives in the unusual case where this was intended by the programmer.

Bibliography

[Bloch 2001]

Item 29, Minimize the scope Scope of local variablesLocal Variables

[JLS 2011]

§14.4, "Local Variable Declaration Statements"

 

...