|
While-Wend Statement |
Top Previous Next |
Function: |
Executes a block of code as long as an expression evaluates to true. |
Syntax: |
while expression statement1 statement2 … [exit sub] … statementN wend |
Scope: |
Local and HTML |
See Also: |
Part |
Description |
expression |
Required. The expression which is to be evaluated. |
statement[1, 2...] |
Required. The code to run when the expression is true. |
Details
Makes a pre-conditional loop. First, the expression is evaluated and then if it is true statement1, statement2, etc are executed. Then expression is evaluated again and so on until expression becomes false.
Examples
function wait_char(ch as byte) as byte ' waits for specific character with ASCII code ch to arrive into the serial port. ' returns 0 if char was encountered or 1 if this character was encountered
dim s as string(1)
' input data byte by byte for as long as there is some data left to process s = ser.getdata(255) ' will input byte by byte as s only can contain a single char! while len(s)<>0 if s = chr(ch) then wait_char = 0 ' character encountered! exit function end if s = ser.getdata(255) wend
wait_char = 1 ' did not encounter ch character and there is no more data to input (for now)!
End Function
|