Cicode Programming Reference > Working with Conditional Executors > Setting IF ... THEN Conditions

Setting IF ... THEN Conditions

The IF statement executes one or more statements based on the result of an expression. You can use If in one of two formats: If Then and If Then Else.

If Expression Then
Statement(s);
END
-or-
If Expression Then
Statement(s);
Else
Statement(s);
END

When you use the If Then format, the statement(s) following are executed only if the expression is TRUE, for example:

INT Counter;
IF PV12 = 10 THEN
Counter = Counter + 1;
END

In this example, the Counter increments only if the tag PV12 is equal to 10, otherwise the value of Counter remains unchanged. You can include several statements (including other IF statements), within an IF statement, for example:

INT Counter;
IF PV12 = 10 THEN
Counter = Counter + 1;
IF Counter > 100 THEN
Report("Shift");
END
END

In this example, the report runs when the Counter increments, that is when PV12 = 10, and the value of the counter exceeds 100.

You can use the If Then Else format for branching. Depending on the outcome of the expression, one of two actions are performed, for example:

INT Counter;
IF PV12 = 10 THEN
Report("Shift");
ELSE
Counter = Counter + 1;
END

In this example, the report runs if PV12 is equal to 10 (TRUE), or the counter increments if PV12 is anything but 10 (FALSE).

See Also

Working with Conditional Executors