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.
.wendx
:nWHILE...WEND statement programming example
◄QuickSCREEN► ◄Details► ◄Example► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
WHILE...WEND Statement Programming Example
The following fragment performs a bubble sort on the array A$.
The second line makes the variable Exchange true by assigning
it a nonzero value, and thereby forces 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