Iterate from 0 to n - i - 1
for j in range ( n - i ) : NEW_LINE INDENT if ( arr [ j ] > arr [ j + 1 ] ) : NEW_LINE INDENT arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ] NEW_LINE flag = True NEW_LINE DEDENT DEDENT if ( flag == False ) : NEW_LINE INDENT break NEW_LINE DEDENT