...
Code Block | ||
---|---|---|
| ||
public class Scope { public static void main(String[] args) { int i = 0; for(i = 0; i < 10; i++) { //do 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 Do operations } } } |
Additionally, methods should be designed to perform only one operation if possible. This reduces the need for variables existing in overlapping scopes and consequently, helps prevent errors.
...