User`s guide
E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 145
Do…Loops
There are a variety of Do …Loops available in E-Basic.
Statement Description
Do…Loop Repeats the block of code until a condition is true and then executes an
End Do statement.
Do…While…Loop Repeats the block of code only while a condition is true.
Do Loop…While Executes the block of code once and then repeats it until the condition
is false.
Do Until…Loop Executes and repeats the block of code only while the condition is false.
Do…Loop Until Executes the block of code once and then repeats it until the condition
is true.
Do While… Loop
The most typically used Do…Loop is the Do While…Loop. The basic syntax is:
Do While condition
<block of statements that are executed while condition is true>
Loop
E-Basic evaluates the condition when it encounters a Do While statement. If the condition is true,
then the block of code within the Loop structure will be executed. When it reaches the Loop
statement, the entire process is repeated including reevaluation of the condition. When the
condition is false, the entire loop structure is skipped and E-Basic executes the next statement
immediately following the Loop statement of the structure. In theory, no limit exists on the
amount of times the block of code within the structure may be executed.
Do…Loop While
The only difference between a Do While…Loop and a Do… Loop While is the location of the
condition. The Do While …Loop evaluates the condition before executing the block of code
within the structure. The Do Loop…While evaluates the condition after executing the block of
code within the structure. The While in this case determines if the block of code within the
structure should be repeated based on the value of the condition. The major resulting difference
is that a Do… Loop While will always execute the block of code at least once.
Do
<block of statements that are executed while condition is true>
Loop While condition
The Do…Loop While structure is useful when the block of code within the structure sets a value
for the condition before it is evaluated. This structure is also useful when performing an action on
an item which has more than one element (e.g., a string or an array). Since the item has at least
one element, execute the block of code at least once and then repeat it based on the total
number of elements within the item.
Do Until…Loop
The Do Until Loop is essentially equivalent to the Do While…Loop structure. They both execute
a block of code after evaluating a condition. The Do While structure will repeat a block of code
until the condition is false. A Do Until structure repeats a block of code until the condition is true.
Do Until condition
<block of statements that are executed while condition is true>
Loop










