title: How do I avoid a useless return in a Java method?
body: <p>I have a situation where the <code>return</code> statement nested in two <code>for</code> loops will always be reached, theoretically.</p>
  
  <p>The compiler disagrees and requires a <code>return</code> statement outside of the <code>for</code> loop. I'd like to know an elegant way to optimize this method that's beyond my current understanding, and none of my attempted implementations of break seem to work.</p>
  
  <p>Attached is a method from an assignment that generates random integers and returns the iterations cycled through until a second random integer is found, generated within a range passed into the method as an int parameter.</p>
  
  <pre><code>private static int oneRun(int range) {
      int[] rInt = new int[range+1]; // Stores the past sequence of ints.
      rInt[0] = generator.nextInt(range); // Inital random number.
  
      for (int count = 1; count &lt;= range; count++) { // Run until return.
          rInt[count] = generator.nextInt(range); // Add randint to current iteration.
          for (int i = 0; i &lt; count; i++) { // Check for past occurence and return if found.
              if (rInt[i] == rInt[count]) {
                  return count;
              }
          }
      }
      return 0; // Never reached
  }
  </code></pre>