Why does this javascript code have an infinite loop?
<p>optionElements is a 2d array. Each element has an array of length 2. These are an integer number and an  element. I have a select list called linkbox, and i want to add all of the  elements to the select list. The order I want them to go in is important, and is determined by the number each element has. It should be smallest to highest. So think of it like this:</p>

<p>optionElements is:</p>

<pre><code>[ [5, &lt;option&gt;], [3, &lt;option], [4, &lt;option], [1, &lt;option], [2, &lt;option]]
</code></pre>

<p>and it would add them to link box in order of those numbers. BUT that is not what happens. It is an infinite loop after the first time. I added the x constraint just to stop it from freezing my browser but you can ignore it.</p>

<pre><code>var b;
var smallest;
var samllestIndex;
var x = 0;
while(optionElements.length &gt; 0 &amp;&amp; ++x &lt; 100)
{
    smallestIndex = 0;
    smallest = optionElements[0][0];
    b = 0;
    while( ++b &lt; optionElements.length)
    {
        if(optionElements[b][0] &gt; smallest)
        {
            smallestIndex = b;
            smallest = optionElements[b][0];
        }                    
    }                    
    linkbox.appendChild(optionElements[smallestIndex][1]);
    optionElements.unshift(optionElements[smallestIndex]);
}
</code></pre>

<p>can someone point out to me where my problem is?</p>

<p><strong>Update</strong></p>

<p>forgot to add the > sign is wrong in the while loop but is not the cause of the problem.</p>
