擅长:python、mysql、java
<blockquote>
<p>[What is] the role of the <code>for</code> loop on the first line of the function. Isn't the <code>while</code> loop doing the iterating and comparisons on the list?</p>
</blockquote>
<p><code>while</code>循环为列表中的一个特定位置找到正确的元素<em>,<code>for</code>循环为每个位置重复搜索<em>(从而对列表进行排序)。你知道吗</p>
<p>所有<code>if</code>条件所做的就是找到那些尚未放置的元素中的最小元素。因此,在<code>for</code>循环的第一次迭代中,算法将找到最小的元素;在第二次迭代中,找到第二小的元素;依此类推。你知道吗</p>