Scope minimization helps developers to avoid common programming errors, improves code readability by tying together connecting the declaration and actual use of a variable, and improves maintainability because unused variables are more easily detected and removed.
...
Minimize the scope of variables where possible, for example, by declaring loop indexes indices within the for
statement.
Code Block | ||
---|---|---|
| ||
public class Scope { public static void main(String[] args) { for (int i = 0; i < 10; i++) { //contains declaration // Do operations } } } |
...