title: Why do I get an error for not having a return statement even though I have one in my for loop?
body: <p>I am writing a method that is part of a Queue class for a college assignment. It is supposed to search a linked list for an object and if it is found return the index of the object, and if it isn't then it returns -1. When I don't have the "return -1;" statement in my code below I get an error saying that I don't have a return statement when I clearly have one above in the for loop. What is the issue here?</p>
  
  <pre><code>    public int find(Object item) {
  
      Node current = head;
  
  
      for(int index = 0; index &lt; size; index++) {
          if(current.data.equals(item)) {
              return index;
          }
          else {
              current = current.next;
          }
      }
  
      return -1;
  
  }
  </code></pre>