...
Code Block | ||
---|---|---|
| ||
public class Scope { public static void main(String[] args) { int i=0; for(i=0;i<10;i++) { //do operations } } } |
Compliant Solution
...
Code Block | ||
---|---|---|
| ||
public class Scope { public static void main(String[] args) { for(int i=0;i<10;i++) { //contains declaration //do operations } } } |
Additionally, methods should be designed for only one operation if possible. This simplicity avoids variables from existing in overlapping scopes and prevents errors.
...