Nested if-statement in loop vs two separate loops
<p>Here is the source code:</p>

<pre><code>public int indexOf(Object o) {
    if (o == null) {
        for (int i = 0; i &lt; size; i++)
            if (elementData[i]==null)
                return i;
    } else {
        for (int i = 0; i &lt; size; i++)
            if (o.equals(elementData[i]))
                return i;
        }
    }
    return -1;
}
</code></pre>

<p>Why doesn't one this: have only one loop and the if-statement. </p>

<pre><code>public int indexOf(Object o) {

   for (int i = 0; i &lt; size; i++){
       if (o == null) {
             if (elementData[i]==null)
                return i;
        else {
             if (o.equals(elementData[i]))
                return i;
        }
    }

    return -1;
}
</code></pre>

<p>The first snippet has to have two loops, but some say the above code performance is good.  Why?</p>
