User`s guide

E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 146
Do…Loop Until
Like the Do While Loop varieties, the Do Until Loop also offers the option of setting when the
condition is evaluated. In this case, the condition is evaluated at the end of the block of code.
Therefore, the block of code is executed at least once.
Do
<block of statements that are executed while condition is true>
Loop Until condition
Do Loops with If..Then or Select Case statements
Exit Do
Occasionally, the Do Loop structure doesn’t quite meet the need for the intended flow. For
instance, a loop may need to be broken immediately within the block of code contained within the
structure. This is accomplished by nesting an If…Then…End If or Select Case structure within
the block of code executed by the Do Loop.
Do While condition1
If condition2 Then
Exit Do
End If
<block of statements that are executed while condition is true>
Loop
Exit Do is particularly helpful in debugging code. Specifically, Exit Do will allow the loop to be
bypassed without having to manually comment out the entire Do Loop structure.
Do
While the previously described varieties of Do Loops evaluate a condition at either the beginning
or the end of a block of code to be executed (and possibly repeated), it is also possible to
evaluate the condition within the actual block of code itself. This requires the use of a nested
If..Then or Select Case structure.
Do
(block of statements to be executed while in the Loop structure)
If condition Then
Exit Do
End If
<block of statements that are executed while condition is true>
Loop
This process is useful when part of the block of code within the loop should be executed, but not
the entire block of code.
For…Next Loops
If the number of times a block of code should be repeated is definite, a For…Next loop structure
is most appropriate. With this structure, the loop is repeated based on the start and end values
supplied. These values can be integers, variable or expressions. A counter is used to keep track
of the number of times the loop is repeated.
For counter = start To end
<block of statements to be executed>
Next counter