beautypg.com

Remarks – Campbell Scientific CR9000X Measurement and Control System User Manual

Page 334

background image

Section 9. Program Control Instructions

Syntax 2

Do

[statementblock]

[

Exit Do

]

[statementblock]

Loop

[{

While

or

Until

} condition]

Remarks
While
or Until with corresponding condition, and Exit Do are not required. If
none of these are used, the Do .. Loop will continue indefinitely.

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.
Once the condition is false, the loop will be exited.

Until

Indicates that the loop is executed while condition is false.
Once the condition is true, the loop will be exited.

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 of the Do...Loop structure.

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

Alternatively, the same thing can be accomplished by incorporating the range
test in the Do...Loop as follows:

Dim Reply

'Declare variable.

DO

Reply = Volt(1)

LOOP UNTIL

Reply > 1 And Reply < 9

9-4