◄Example► ◄Contents► ◄Index► ◄Back► ────────────────────────────────────────────────────────────────────────────── 'This example uses the SWAP statement to exchange array elements that are 'out of order. The program sorts a string array in descending order using 'a shell sort. Num% = 4 Array$(1) = "New York" Array$(2) = "Boston" Array$(3) = "Chicago" Array$(4) = "Seattle" Span% = Num% \ 2 DO WHILE Span% > 0 FOR I% = Span% TO Num% - 1 J% = I% - Span% + 1 FOR J% = (I% - Span% + 1) TO 1 STEP -Span% IF Array$(J%) <= Array$(J% + Span%) THEN EXIT FOR ' Swap array elements that are out of order. SWAP Array$(J%), Array$(J% + Span%) NEXT J% NEXT I% Span% = Span% \ 2 LOOP CLS FOR I% = 1 TO Num% PRINT Array$(I%) NEXT I% END