Campbell Scientific CR5000 Measurement and Control Module User Manual

Page 211

Advertising
background image

Section 9. Program Control Instructions

9-5

Do

Repeats a block of statements while a condition is true or until a condition
becomes true.

Syntax 1
Do
[{While | Until} condition]

[statementblock]
[Exit Do]
[statementblock]

Loop

Syntax 2
Do

[statementblock]
[Exit Do]
[statementblock]

Loop [{While | Until} condition]

The Do...Loop statement has these parts:

Part

Description

Do

Must be the first statement in a Do...Loop control structure.

While

Indicates that the loop is executed while condition is true.

Until

Indicates that the loop is executed until condition is true.

condition

Numeric expression that evaluates true (nonzero) or false (0
or Null).

statementblock

Program lines between the Do and Loop statements that are
repeated while or until condition is true.

Exit Do

Only used within a Do...Loop control structure to provide an
alternate way to exit a Do...Loop. Any number of Exit Do
statements may be placed anywhere in the Do...Loop. Often
used with the evaluation of some condition (for example,
If...Then), Exit Do transfers control to the statement
immediately following the Loop. When Do...Loop
statements are nested, control is transferred to the Do...Loop
that is one nested level above the loop in which the Exit Do
occurs.

Loop

Ends a Do...Loop.

Do...Loop Statement Example

The example creates an infinite Do...Loop that can be exited only if Volt(1) is
within a range.

Dim Reply

'Declare variable.

Do

Reply = Volt(1)
If Reply > 1 And Reply < 9 Then

'Check range.

Exit Do

'Exit Do Loop.

End If

Loop

Advertising