I'm trying to spiff-up my skills and thought I would try to write my own little sorting algorithm:
import random
from random import randint
int_list = []
for i in range(10): #Creates a 10-entry list of randon ints
int_list.append(random.randint(0,10))
print "Unsorted list:\t" + str(int_list)
def sorter(int_list):
for i in range(len(int_list)-1):
while int_list[i] > int_list[i+1]:
temp = int_list[i]
int_list[i] = int_list[i+1]
int_list[i+1] = temp
continue
return int_list
print "\"Sorted\" list:\t" + str(sorter(int_list))
When I run this script it only sorts the first two entries of the list. My understanding of continue was that it would keep looping through my while loop while the while statement was True.
continueis doing nothing. You can (should) remove it no problem.continuejust stops the execution of the current iteration and starts the next.tempvariable to swap two values, simply do:int_list[i], int_list[i+1] = int_list[i+1], int_list[i]:)continue.