' Array Sort/Scan — ARRAY SORT and ARRAY SCAN operations
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i AS LONG
    LOCAL idx AS LONG
    LOCAL r AS LONG
    LOCAL line AS STRING

    DIM nums(1 TO 8) AS LONG
    nums(1) = 42
    nums(2) = 7
    nums(3) = 99
    nums(4) = 13
    nums(5) = 55
    nums(6) = 3
    nums(7) = 88
    nums(8) = 24

    PRINT "Unsorted:"
    line = ""
    FOR i = 1 TO 8
        r = nums(i)
        line = line + STR$(r) + " "
    NEXT i
    PRINT line
    PRINT

    ARRAY SORT nums
    PRINT "Sorted ascending:"
    line = ""
    FOR i = 1 TO 8
        r = nums(i)
        line = line + STR$(r) + " "
    NEXT i
    PRINT line
    PRINT

    ARRAY SORT nums, DESCEND
    PRINT "Sorted descending:"
    line = ""
    FOR i = 1 TO 8
        r = nums(i)
        line = line + STR$(r) + " "
    NEXT i
    PRINT line
    PRINT

    ARRAY SCAN nums, EQUAL, 88, TO idx
    PRINT "ARRAY SCAN for 88: index " + STR$(idx)

    ARRAY SCAN nums, EQUAL, 99, TO idx
    PRINT "ARRAY SCAN for 99: index " + STR$(idx)

    FUNCTION = 0
END FUNCTION
