Branch Statement

IF Statement

IF Statement performs the operations in the statement if the conditional expression’s result is "1"
If IF Statement’s condition is false and there’s ELSIF, the condition of ELSIF is examined.
If all the conditions are false, none of the command statements are performed unless there is an ELSE.


Format

IF Conditional_Expression THEN

   Syntaxes

ELSIF Conditional_Expression THEN

   Syntaxes

(Omit)

ELSE

   Syntaxes

END_IF;

 Conditional Expressions can be composed of Comparison Operation or Logical Operation
There can be multiple Syntaxes.
Multiple number of ELSIF can be used. ELSE can only be used once or not used at all.


Example

Description

// IF D1’s value is 0, assign 1 to D100

IF DW01 = 0 THEN

   DW100 := 1;

// If D1’s value is 1, assign 2 to D100

ELSIF DW01 = 1 THEN

   DW100 := 2;

// If D1’s value is less than 5, assign 3 to D100

ELSIF DW01 < 5 THEN

   DW100 := 3;

// If D1’s value is not 0 or 1 and equal to or greater than 5, assign 0 to D100

ELSE

   DW100 := 0;

END_IF;

 

CASE Statement

CASE Statement branches the following operations according to the expression’s value.


Format

CASE Expression OF

Integer_Option : Syntaxes

Integer_Option : Syntaxes

(Omit)

ELSE

   Syntaxes

END_CASE;

The Expression must be integer.
Integer_Option can be either singular integer, multiple integers or the range of integers.

Integer_Option types

Description

1

When the Expression’s value is 1

2, 3, 4

When the Expression’s value is 2, 3, 4

5..10

When the Expression’s value is from 5 to 10 (5, 6, 7,  8, 9, 10)

1, 2..5, 10

When the Expression’s value is 1, 2 to 5, and 10 (1, 2, 3, 4, 5, 10)

There can be multiple Syntaxes.
ELSE can only be used once or not used at all.

Example

Description

 

CASE DW10 OF

// If D10’s value is 4, assign 4 to D0

4:

   DW00 := 4;

// If D10’s value is between 5 to 6 or 7, assign 5 to D0

5..6, 7:

   DW00 := 5;

// If D10’s value is 4 or between 5 to 6 or not 7, assign 0 to D0

ELSE

   DW00 := 0;

END_CASE;