previous | start | next

Scope: Example 1

Compile Error at line 12.

The scope of the declaration of i at line 7 is lines 7 - 10; that is, this i is only accessible on those lines.

    1   /**
    2    * Returns the index in array s such that s[i] is equal to x
    3    * or returns -1 if there is no such index.
    4    */
    5   public int indexOf(String[] s, String x)
    6   {
    7      for(int i = s.length - 1; i >= 0; i--) {
    8         if (x.equals(s[i])) {
    9            break;
   10         }
   11      }
   12      return i;
   13   }


previous | start | next