Versions Compared

Key

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

...

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

Compliant Solution

...

Code Block
bgColor#ccccff
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.

...