title: Searching for specific value in array with while-loop
body: <p>I have the task to build a method to search for an identical value for a variable in an array.
  When there is a match, the method will return the index-Position, otherwise it should return -1.</p>
  
  <p>My method works when there is a match, but I get an error when there isn´t any match.</p>
  
  <p>My Code so far:</p>
  
  <pre><code>public class Schleifentest {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          int [] cherry = {7,5,6,8,9};
          int magNumber = 112;
          int enthalten2 = Schleifentest.sucheWhile(cherry, magNumber);
          System.out.println(enthalten2);
  
  
      }
  
      public static int sucheWhile(int [] array, int a) {
          int i = 0;
          while(i &lt;= array.length) { 
              if (array[i] == a) {
                  return i;
              }
              i++;
  
          }
          // here is the problem
          return -1;
      }
  
  }
  </code></pre>
  
  <p>Thanks  for your help.
  Phil</p>