' Array sort and scan
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL arr(10) AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL t AS LONG
    arr(0)=9:arr(1)=4:arr(2)=7:arr(3)=2:arr(4)=1
    arr(5)=8:arr(6)=3:arr(7)=6:arr(8)=0:arr(9)=5
    FOR i = 0 TO 8
        FOR j = i+1 TO 9
            IF arr(i) > arr(j) THEN t=arr(i):arr(i)=arr(j):arr(j)=t
        NEXT j
    NEXT i
    t = 0
    FOR i = 0 TO 9
        t = t + arr(i)
    NEXT i
    PRINT "Sorted sum=" + STR$(t)
    PRINT "Done."
    FUNCTION = 0
END FUNCTION
