User`s guide

E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 144
If…Then…Else statements
If the program must choose between two alternative blocks of code to execute based on the
conditional, then the Else statement is included.
Dim a As Integer
a = 12
If a > 10 Then
MsgBox "A is greater than 10."
Else
MsgBox "A is not greater than 10."
End If
Select Case statements
Nested If…Then statements are ideal for testing different values before executing the next block
of code. Select Case statements are more appropriate for testing the same value against many
different conditions.
Select Case variable
Case test1
<block of code statements to be executed if the
value of variable meets test1 criteria>
Case test2
<block of code statements to be executed if the
value of variable meets test2 criteria>
Case Else
<block of code statements to be executed if the
value of variable doesn’t meet any of the
listed Case criteria above>
End Select
The Select Case structure indirectly uses condition expressions. An expression may be A + B >
C. In the example above, think of the variable being what is to the left of the operator (A + B) and
test as everything to the right, including the operator (>C).
Rules:
An unlimited number of cases may be used as test criteria.
The Else case is optional. It is not required to be used, but can be useful in behavioral
research.
4.5.2.2 Loops
The loop flow control structures are also quite commonly used in programming. They are useful
when a block of code needs to be executed more than once. There are three major types of
loops available in E-Basic: Do…Loop, For…Next, and For Each…Next.
Type of Loop Function
Do…Loop Repeats the block of code until a condition is true.
For…Next Repeats the block of code a specified number of times.
For Each…Next Repeats the block of code for each object within a collection.