Beckhoff Automation GmbH & Co. KG TX1200 — 2.2.3.5 CASE instruction

A Brief Introduction to TwinCAT PLC Control counter := counter-1; END_WHILE The WHILE and REPEAT loops are, in a certain sense, more powerful than the FOR loop since one doesn't need to know the number of cycles before executing the loop. In some cases one will, therefore, only be able to work with these two loop types. If, however, the number of the loop cycles is clear, then a FOR loop is preferable since it allows no endless loops. 2.2.3.4 IF instruction With the IF instruction you can check a condition and, depending upon this condition, execute instructions. Syntax: IF THEN {ELSIF THEN . . ELSIF THEN ELSE } END_IF; The part in braces {} is optional.

If the returns TRUE, then only the are executed and none of the other instructions. Otherwise the Boolean expressions, beginning with , are evaluated one after the other until one of the expressions returns TRUE. Then only those instructions after this Boolean expression and be-fore the next ELSE or ELSIF are evaluated. If none of the Boolean expressions produce TRUE, then only the are evaluated. Sample: IF temp THEN heating_on := TRUE; ELSE heating_on := FALSE; END_IF; Here the heating is turned on when the temperature sinks below 17 degrees. Otherwise it remains off.

2.2.3.5 CASE instruction With the CASE instructions one can combine several conditioned instructions with the same condition variable in one construct. Syntax: CASE OF : : ... : TX1200 22 Version: 1.3