title: Return statment not working in Java
body: <p>I have been trying a small code to learn about recursion in java. Wrote the below method to implement linear search using recursion. But when I call this method with an array and the variable to search as input and when the method reaches the return statement, it is not exiting the method. Instead, after executing the statements in the if loop, it's once again entering the else loop.</p>
  
  <p>I have 2 questions.</p>
  
  <p>1) Why is it not exiting the method on reaching 'return' ?</p>
  
  <p>2) Why is it entering the else loop after executing the if loop ?</p>
  
  <p>What am I doing wrong here ? Can someone please take a look and help me.</p>
  
  <pre><code>linearRecursiveSearch(Constants.INPUT_INT_ARRAY, Constants.INPUT_INT_ARRAY[0], Constants.NUMBER_TO_SEARCH); 
  
  
  
  int count = 0;
  public &lt;T&gt; void linearRecursiveSearch(T[] array,T tmp, T value) {
      count++;
      if (tmp == value) {
          System.out.println("The value has been found");
          return;
      } else {
          for (int i = count; i &lt; array.length; i++) {
              T tmp1 = array[i];
              linearRecursiveSearch(array,tmp1, value);
          }
      }
  }
  </code></pre>