def sort(a_list): for i in range(1,len(a_list)): print("i=",i) for j in range(i-1,0,-1): print("j=",j)
Test: L=[9,6,1,3]
i= 1 i= 2 # here, the outer lopp ran twice then inter loop began. j= 1 i= 3 j= 2 j= 1
i
j
range
i - 1
range(1 - 1, 0, -1)
Quote:why the outer loop run twice before the inter loop get a chance to run?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)