SWAP Statement ---------------------------------------------------------------------------- Action Exchanges the values of two variables. Syntax SWAP variable1, variable2 Remarks Any type of variable can be swapped (integer, long, single precision, double precision, string, currency, or record). However, if the two variables are not exactly the same data type, BASIC generates the error message Type mismatch. Example The following example sorts the elements of a string array in descending order using a shell sort. It uses SWAP to exchange array elements that are out of order. ' Sort the word list 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