I think you are forgetting that the loop is going from the end of the list to the beginning. If you take the list you gave as input and follow the process you will get the result [10, 30, 40, 20, 60, 50]. Which is the right one. Just do it in paper and you will see.