' *** DECL_EX.BAS - DECLARE statement programming example ***
' This program uses DECLARE to allow you to invoke
' a subprogram, Sort, without using the CALL keyword.
' The program generates 20 random numbers, stores them
' in an array, and sorts them.
'
DECLARE SUB Sort (A() AS SINGLE, N AS INTEGER)
DIM Array1(1 TO 20)
CLS    ' Clear screen

' Generate 20 random numbers.
RANDOMIZE TIMER
FOR I = 1 TO 20
   Array1(I) = RND
NEXT I

' Sort the array and call Sort without using the CALL keyword.
' Note that there are no parentheses around the arguments in
' the call to Sort.
Sort Array1(), 20

' Print the sorted array.
FOR I = 1 TO 20
   PRINT Array1(I)
NEXT I
END

' Sort subroutine.
SUB Sort (A(), N%) STATIC

   FOR I = 1 TO N% - 1
      FOR J = I + 1 TO N%
         IF A(I) > A(J) THEN SWAP A(I), A(J)
      NEXT J
   NEXT I

END SUB

