Programming, 9 control structures, 1 if structure – Lenze E94P PositionServo with MVOB User Manual

Page 46

Advertising
background image

44

L

PM94H201B_13xxxxxx_EN

Programming

2.9

Control Structures

Control structures allow the user to control the flow of the program’s execution. Most of the control and flexibility of any
programming language comes from its ability to change statement order with structure and loops.

2.9.1 IF Structure

The flowchart and code segment in Figure 17 illustrate the use of the IF statement. The “IF” statement is used to execute
an instruction or block of instructions one time if a condition is true. The simplified syntax for the IF statement is:

IF condition

…statement(s)

ENDIF

…statements

IF IN_A2

OUT2 = 1

MOVED 3

ENDIF

..statements

Start

Set Output 2 ON

Move Distance 3

units

End

Yes

NO

Input A2 ON?

Figure 17: IF Code and Flowchart

IF/ELSE

The flowchart and code segment in Figure 18 illustrate the use of the IF/ELSE instruction. The IF/ELSE statement is
used to execute a statement or a block of statements one time if a condition is true and a different statement or block of
statements if condition is false. The simplified syntax for the IF/ELSE statement is:

IF <condition>

…statement(s)

ELSE

…statement(s)

ENDIF

…statements

IF IN_A2

OUT2=1

MOVED 3

ELSE

OUT2=0

MOVED 5

ENDIF

..statements

Start

Input A2 ON?

Set Output 2 ON

Move Distance 3

units

End

Yes

Set Output 2 OFF

Move Distance 5

units

No

Figure 18: IF/ELSE Code and Flowchart

Advertising