Equinox Online Help - Language Reference - A to Z

Home

If ... Then

Applies to
SyntaxIf TestExpression Then statement [Else If statement] [Else statement]

Also

if TestExpression then
statements
[Exit If]
[ElseIf TestExpression then
[statements]
[else]
[statements]
end if

Note that you can use EndIf instead of End If.

Action[Statement] TestExpression is evaluated and the result determines whether or not the enclosed statements are executed.
ScopeUsable anywhere.
Notes

There are two forms of the If statement, both of which are shown above. The first must be on one logical line and no End If statement should be included.

The second can occupy several lines, but the first line must end with Then and last line must be End If. The second form has the advantage that it allows more than one line with each of the Then and Else clauses.

If TestExpression is evaluated as True then the statement(s) following Then and preceding the first Else, ElseIf or End If execute. If the condition is False and Else is included, then the statement(s) following Else and preceding End If execute. Note that you can use the Exit If statement to Exit the If structure at any point.

You can nest If statements in either form using Else If. If the first condition is False then the condition following ElseIf is evaluated. If this second expression is True, the following statement(s) are executed. Note that nested Else clauses belong to the closest If statement.

Consider Logical expressions and Evaluating a mixed type expression for more information

If statements may include list expressions. eg The following line tests for a number of values:

if Number = 1,7,10 then ...

This is equivalent to:

if Number = 1 Or Number = 7 Or Number = 10 then ...

You should note that TestExpression is assumed to be a logical expression, unless it is enclosed brackets. If enclosed in brackets, then it is evaluated as a binary expression. eg:

if (BitField And BitMask) then ...
CategoryFlow Control
See Also Block_EndBlock, BreakPressed, Continue, Execute, EnableInput, Exit, For...Next, Goto, If_Then, Repeat_Until, Return, Sleep, Subtable, Switch, While_EndWhile
Example

This example tests the SysMode workarea, to determine if a record is being edited or inserted. If so, then it is saved before the form group is changed.

If SysMode = EditMode, InsertMode Then SaveRecord
ChangeGroup "customer"

The next example has exactly the same function, but uses the alternative If syntax.

if SysMode = EditMode, InsertMode then
SaveRecord
end if

ChangeGroup "customer"