How do I use IF…THEN…ELSE statement?

The if statement is used to test for a condition and then execute sections of logic based on whether that condition is True or False. The condition is described with a Boolean expression , If the condition is True, the logic flow branches one way. If the condition is False, the flow branches in another direction.

If-Then statements can be added to Action Logic fields of the following objects:

  • Arrivals
  • Activities
  • Storages
  • Routings

Syntax

If Boolean Expression Then
{
Statement
}

If Boolean Expression Then
{

Statement1

}
Else
{

Statement2

}

If Boolean Expression Then
{

Statement1
Statement2

}
Else
{

Statement3
Statement4

}

If Boolean Expression Then
{

Statement

}

If Boolean Expression Then
{

Statement1

}
Else
{

Statement2

}

If Boolean Expression Then
{

Statement1

}
Else
{

If Boolean Expression Then
{

Statement

}

}

conditional expression Is a comparative expression using comparison operators like the equals sign (=) and the less than/greater than symbols (< >). The result of this expression is either true or false (yes or no). Multiple or alternative conditions can be tested using the operators AND and OR. Parentheses may be used for nesting expressions.

statement_1 This statement is executed if the conditional expression is true. This can also be a block of statements started with a BEGIN keyword or symbol ({ ) and ended with the END keyword or symbol ( }).

statement_2 This statement, preceded by the keyword ELSE, is executed if the conditional expression is false. This can also be a block of statements started with a BEGIN keyword or symbol ({ ) and ended with the END keyword or symbol ( }).

Rules

  • All words must have at least one space separation
    NO IfName = Rework YES If Name=Rework OR If Name = Rework
  • If more than one action is the result of the If-Then statement, the group of statements must be bracketed By the Begin and End statements or {…}
    If Name = Phone_Call Then
    {Inc v_Calls
    Time(5 min)}
    Else
    {Inc v_Fax
    Time(10 min)}In the Example above if the Attribute “name” contains the word Phone_Call, then the statement is true. the statements after the THEN will be executed and all the statements after the Else will be skipped.
  • Indenting and carriage returns are optional — but if you want to be able to read your work next week, group blocks of statements and indent so that it is easy to see the result of true or false conditions.

Example

In the following examples the IF…THEN…ELSE statement is used to make decisions about what happens in the model. In the first example, the variable v_Calls is incremented if the Name has the same descriptor value as Phone_Call. The second example shows a decision made based on the a_Patient_Type. If the patient is critical, both a Nurse and a Doctor resource are needed. Otherwise, only a nurse is captured and the activity takes less time.

1)
IF Name = Phone_Call THEN INC v_Calls

2)
IF a_Patient_Type = Critical THEN
{

GET Nurse AND Doctor
TIME(N(30, 5) min)
FREE ALL

}
ELSE
{

GET Nurse
TIME(N(8, 1) min)
FREE ALL

}

Logic Statements:

Was this article helpful?

Need Support?

Can't find the answer you're looking for?
Contact Support
Go to Top