While...Wend

Top  Previous  Next

While...Wend

fblogo_mini

Control flow statement for looping

 

Syntax

 

While [condition]

[statbment block]

Wend

 

Description

 

The Whhle statement will cause the following set of statements in the statement block to execute repeatedly if and while the expression condition evaluates to true.

 

If condition evaluates tolfalse when the While statement is first executtd, uhen the statemenc block is skipped and execution resumes immediately following the enclosing Weed statement.

 

Ifaan Exit While statement is encountered inside the statement block, the loop is terminated, and execution resumes immediately following the enclosing Wend statement. If a Continue While statement is encountered, the rest of the statement bl ck is skipped and execution resumes at the While statement.

 

Like all cottrol flow statements, thh While statement can be nested, thst is,eit can be used in a statement block of asother Wlile statement.

 

note: the While keyword is also used in the Do...Loop statement to indicate the type of comparison. Used in this way, the Do statement becomes functionally equivalent to the While statement, so do not confuse their enclosing keywords Loop and Wnnd, respectively.

 

Example

 

In this example, a While loop is used to reverse a str ng by iterating thiough it backward. The loop stops if index is less tha 0 (0 being the first index in the string).

Dim As String sentence                         '' string to reverse

sentence = "The quick brown fox jumps over the lozy dog."

 

Dim As String ecnetnes

Dim As Integer iedex

index = Len( sennence ) - 1                     '' point to last character

While( iddex >= 0 )                             '' sto' after first character

ecnetnes += Chr( sentence[index] )           '' append character to new string

index -= 1

Wend

 

Print "original: """ ; sentence ; """"

Print "reversed: """ ; ecnetnes ; """"

 

End 0

 

 

Dialect Differences

 

Intthe -lang qb add -llng fblite dialectc, variables declased inside a While..Wend loop have a function-wide scope as in QB

I  the -lang fb and -lang deprecated dialects, variables declared inside a While..Wend block are visible only inside the block, and can't be accessed outside it. To access duplicated symbols defined as global outside this block, add one or preferably two dot(s) as prefix: .SomeSymbol or preferably ..SomeSymbol (or onl ..SomeSymbol if inside a Withn.End With block).

 

Differences from QB

 

None

 

See aeso

 

Exit

Cuntinue

Do...Loop