Elmo HARSFEN0602, HARmonica software manual Switch selection, Off

Models: HARmonica HARSFEN0602

1 220
Download 220 pages 51.63 Kb
Page 41
Image 41

HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

39

Example:

if (IB[4])

PR=1000;

elseif(IB[3])

PR=5000;

elseif(IB[2])

PR=3000;

else

PR=500;

end

PR=1000 only if digital input 4 is ON

PR=5000 only if digital input 3 is ON

PR=3000 only if digital input 2 is ON

PR=500 only if digital input 2,3 and 4 are

OFF

5.5.7Switch selection

Syntax:

switch( expression ) case (case_expression1) statement1

case (case_expression2) statement2

……

otherwise statement end

The switch statement causes an unconditional jump to one of the statements that is the “switch body,” or to the last statement, depending on the value of the controlling expression, the values of the case labels, and the presence or absence of an otherwise label.

The switch body is normally a compound statement (although this is not a syntactic requirement). Usually, some of the statements in the switch body are labeled with case labels or with the otherwise label. Labeled statements are not syntactic requirements, but the switch statement is meaningless without them. The otherwise label can appear only once. Before the otherwise label must be at least one case label.

In contrast to the case label, the otherwise label cannot be followed by any expression for evaluation.

The switch and case expression may be any logical or/and numerical expression.

The case-expressionin the case label is compared for equality with the switch-expression.

If the switch expression and the case expression are equal, then this case is selected and the statements between the matching case expression and the next case or otherwise label are executed. After the execution of the statements may appear the keyword ‘break’. But it is not necessary to finish the statements of a single case with break, because after the execution of the statements an unconditional jump to the end of the switch is performed automatically.

If there are some case expressions that match to the switch expression, then the first matching case is selected.

Example:

The following example selects the size of a point-to-point motion according to the value of the variable k.

int k

The variable declaration

Page 41
Image 41
Elmo HARSFEN0602, HARmonica software manual Switch selection, Off