while...wend - while statement


while NumExpr

(loop statements)



The while...wend statement is used to perform looping based on the continued truth of a logical expression with the evaluation of this expression occurring at the top of the loop; i.e.  prior to each pass through the loop.  Upon encountering the while, NumExpr is evaluated.  If it has a non-zero value ("true"), the loop statements are executed in sequence until wend is encountered.  At this point, NumExpr is again evaluated and the entire process repeats.  If NumExpr is non-zero (true), another pass through the loop statements occurs.  If NumExpr is zero (false), the loop is exited and the statement immediately following wend is the next to be executed. 

There is no limit on the depth of while...wend loop nesting.  Each wend is matched to the lexically nearest unmatched while. 


This example sorts the elements of the string array a$ into lexicographic order based on the ASCII representation.  a$ was defined with j elements. 
	undone = 1
	while undone
		undone = 0
		for i = 1 to j - 1
			if a$(i) > a$(i + 1) then_
				swap a$(i), a$(i + 1) : undone = 1
		next i


from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber