While...Wend Structure

Purpose

A terminal program loop which runs until the condition at the beginning of the loop is logically "true".

Syntax

While condition
...
// programsegmemt
...
[Exit Do | Exit If... | EndDo]
Wend | EndWhile

condition: any numeric, logical or string condition

Description

The start of a While...Wend loop must contain a numeric, logical or string condition, which is evaluated before each execution of the body of the loop. If the condition is logically "true", the body of the loop is executed. Otherwise, a branch is taken to the program statement immediately after Wend.

The While...Wend loop is an entry tested loop. This means that the loop executes only when the condition at the beginning of the loop is logically "true". By using an Exit If... or Exit Do command, the While...Wend loop can be terminated regardless of whether the loop condition is fulfilled. EndDo can be used as well.

EndWhile is synoymous with Wend

Example

While Not Upper$(InKey$) = "A"

Exit If MouseK = 2

Wend // or EndWhile if you prefer

A loop which runs as long as no lowercase or uppercase "a" is entered from the keyboard or the right mouse button is not pressed.

Remarks

The While...Wend loop can be seen as a logical negation of the Repeat...Until loop, whereby a While Not corresponds to an Until.

See Also

For, Repeat, Do, For Each

{Created by Sjouke Hamstra; Last updated: 04/03/2017 by James Gaite}