qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
WHILE...WEND statement programming example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
WHILE...WEND Statement Programming Example
 
This example performs a bubble sort on the array A$. Assigning the
variable Exchange a nonzero value makes it true, forcing one pass
through the WHILE...WEND loop (this construction is unnecessary with
DO...LOOP). When there are no more swaps, all elements of A$ are
sorted, Exchange is false (equal to zero), and the program continues
execution with the line following WEND.
 
' Bubble sort of array A$.
CONST FALSE=0, TRUE=NOT FALSE
DIM A$(4)
A$(1) = "New York"
A$(2) = "Boston"
A$(3) = "Chicago"
A$(4) = "Seattle"
Max = UBOUND(A$)
Exchange=TRUE           ' Force first pass through the array.
WHILE Exchange          ' Sort until no elements are exchanged.
   Exchange=FALSE
   ' Compare the array elements by pairs. When two are exchanged,
   ' force another pass by setting Exchange to TRUE.
   FOR I = 2 TO Max
      IF A$(I-1) > A$(I) THEN
         Exchange = TRUE
         SWAP A$(I - 1), A$(I)
      END IF
   NEXT
WEND
CLS
FOR I = 1 TO 4
   PRINT A$(I)
NEXT I
END
 
Sample Output
Boston
Chicago
New York
Seattle