If…Then…Else…End Statement (FPScript)

23.08.2021

Evaluates an expression and executes a series of statements, depending on the result.

Syntax

If Condition Then

   [Statements]

[ElseIf Condition n Then

   [ElseIfStatements]] . . .

[Else

   [ElseStatements]]

End

The syntax of the If...Then...Else...End statement consists of the following elements:

Element

Description

Condition

An expression that results in TRUE, FALSE or any numeric scalar value. For the numerical result, all values not equal to zero are taken to be TRUE.

Statements

One or more statements that are executed if Condition has the value TRUE.

Condition n

Means the same as Condition.

ElseIfStatements

One or more statements that are executed if the associated condition (Condition n) results in true.

ElseStatements

One or more statements that are executed if the none of the conditions (Condition or Condition n) result in the value TRUE.

Remarks

When executing an If block, Condition is checked first. If Condition results in the value TRUE, then the statements after Then are executed. If Condition results in the value FALSE, then the ElseIf conditions (if present) are evaluated in sequential order. If one of these conditions results in the value TRUE, the statements after the associated Then are executed. If none of the ElseIf conditions result in the value TRUE (or there are no ElseIf sections present), then the statements after Else are executed. After the statements following a Then or Else section have been executed, the program continues the execution with the statement after End.

The Else and ElseIf sections are optional. In an If block you can use any number of ElseIf sections; after an Else section no ElseIf sections are permitted. If blocks can be nested (i.e. can themselves contain If blocks).

Available in

FlexPro View, Basic, Professional, Developer Suite

Example

The following example restricts all values in a signal to the interval [-5, 5]. It corresponds to Clip(Signal, -50., 5.).

Arguments Signal

For Each Row i In Signal Do

    If Signal.Y > 5 Then

        Signal.Y = 5

    ElseIf Signal.Y < -5 Then

        Signal.Y = -5

    End

End

Signal

 

See Also

Conditional Function

Share article or send as email:

You might be interested in these articles