execution failure of an self insertion_sort definition in python3
<p>I want to put the numbers from the smallest to the largest.</p>

<p>NO.1  succeed</p>

<pre><code>def insertion_sort(list):
    for index in range(1,len(list)):
        value = list[index]
        i = index-1
        while i &gt;=0:
            if value &lt; list[i]:
                list[i+1]=list[i]
                list[i] = value
                i = i-1
            else :
                break
a=[2,1,4,3,6,7,9,5]
insertion_sort(a)
print(a)
</code></pre>

<p>NO.2 failed</p>

<pre><code>def insertion_sort(list):
    for index in range(1,len(list)):
        value = list[index]
        i = index - 1
        while i&gt;=0:
            if value &gt; list[i]:
                i=i-1

            else :
                list[i+1]=list[i]
                list[i]=value
            break


a=[1,3,2,7,4,6,5]
insertion_sort(a)
print(a)    
</code></pre>

<p>when I ran the second, it returned <code>[1, 2, 3, 4, 6, 5, 7]</code></p>

<p>I don't know why and if I remove <code>break</code>, in the second one, it won't return a result, why? I thought the for loop will close itself.</p>

<p>Implementation of insertion sort (without sentinel) should look like;</p>

<pre><code>def insertion_sort(list_):
    for index in range(1,len(list_)):
        value = list_[index]
        i = index - 1
        while i &gt;= 0 and list_[i] &gt; value :
             list_[i + 1] = list_[i]
             list_[i] = value
             i = i - 1
    return list_
</code></pre>

<p>Also remember to not named your list argument <code>list</code> because it's python builtin class.</p>

python