Conditional Functions

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs - Predefined Functions

If Statements

Syntax

Any of the following forms may be used:

Example 1
Single Condition and Single Outcome
Example 2
Single Condition, outcome when true or False
Example 3
Multiple conditions, multiple outcomes
if (expression1)
	statements1
endif
if (expression1)
	statements1
else
	statements2
endif

See also: IIf function

if (expression1)
	statements1
elseif (expression2)
	statements2
elseif (expression3)
	statements3
;etc...
else
	statementsN
endif


All expressions must resolve into a single Boolean (true or false) result.

statements1 : are executed if expression1 is True, otherwise they are ignored.
statements2 : are executed if expression1 is False and expression2 is True, otherwise they are ignored.
statements3 : are executed if both expression1 and expression2 are False and expression3 is True, otherwise they are ignored.
statementsN : is executed if all preceding expressions are false.

  • ElseIf and hence the associated expression2 and statements2 etc - are optional.
  • numerous ElseIfs are allowed, before the Else/EndIf.
  • else and hence the associated statementsN - are optional.
  • If, EndIf keywords (and their associated ElseIf, Else keywords ) can be nested (included within other If-EndIf statements.


Examples

Example 1:

if (FeedFlow > 0.00001)
   Recovery = Product/FeedFlow 
endif

Example 2:

if (FeedFlow == 0)
   Recovery = 0
else
   Recovery = Product / FeedFlow 
endif

See also: IIf function

Example 3:

if (UnitTemperature > 100)
   Reaction_Extent = 98
elseif (UnitTemperature > 80)
   Reaction_Extent = 82
elseif (UnitTemperature >= 30)
   Reaction_Extent = 75
else
   Reaction_Extent = 43
endif

IIf

Syntax

variable = IIf(expression, truePart , falsePart)

expression : must eventually resolve into a single boolean (true or false) result.
truePart  : Value or expression.
falsePart  : Value or expression.

The IIf function, returns one of two parts depending on the evaluation of an expression. The expression is evaluated, if the expression result is true then truePart is evaluated and returned as the result of the IIf function. If the expression result is false then falsePart is evaluated and returned as the result of the IIf function. Note that only one of the two parts is evaluated.

Examples

Example 1:

Recovery = iif(FeedFlow>0.0000001, Product/FeedFlow, 0)

This is equivalent to the following statements using 'if' and 'else':

if (FeedFlow>0.0000001)
  Recovery  = Product/FeedFlow
else
  Recovery  = 0
endif

Example 2:

ReactionExtent = iif(AutoclaveTemperature>=190, 98, 50)

This is equivalent to the following statements using 'if' and 'else':

if (AutoclaveTemperature>=190)
  ReactionExtent = 98
else
  ReactionExtent = 50
endif

IIfStr

This function is available in Build139.29680 and later.

Syntax

String variable = iifstr(expression, truePart , falsePart)

expression : must eventually resolve into a single boolean (true or false) result.
truePart  : String value or string expression.
falsePart  : String value or string expression.

The iifstr function, returns one of two parts depending on the evaluation of an expression. The expression is evaluated, if the expression result is true then truePart is returned as the result of the iifstr function. If the expression result is false then falsePart is returned as the result of the iifstr function. Note that only one of the two parts is evaluated.

Example

Checkbox Controller_On*
String Control_Status@ 

Control_Status = iifstr(Controller_On, "Control is Automatic", "Control is Manual")

While Statements

Syntax

While (expression)
    Statements
EndWhile

expression : must eventually resolve into a single boolean (true or false) result.
statements : will repeatedly be executed while the expression is true (non zero).

If the expression is false, the statements will be ignored.

  • A While ... EndWhile block is an excellent way of implementing a loop.
  • While instructions can be nested.
  • There is no limit to the number of statements inside the While ... EndWhile block.

Examples

Integer LoopCount*
 
LoopCount = 5
 
while (LoopCount>0)
   ; *** do loop logic here ***
   LoopCount = LoopCount - 1
   ; *** or do loop logic here ***
EndWhile