Introduction
A CASE statement helps you choose one action from many options based on a value. It makes your program clear and easy to read.
CASE expression OF
value1:
// actions for value1
value2:
// actions for value2
ELSE
// actions if no value matches
END_CASE;CASE mode OF 1: motor := ON; 2: motor := OFF; ELSE motor := STOP; END_CASE;
CASE errorCode OF 0: status := 'OK'; 1: status := 'Warning'; 2: status := 'Error'; END_CASE;
PROGRAM PLC_CaseExample VAR command : INT := 2; action : STRING; END_VAR CASE command OF 1: action := 'Start'; 2: action := 'Stop'; 3: action := 'Pause'; ELSE action := 'Unknown'; END_CASE; // Output action END_PROGRAM
CASE statement in PLC programming?CASE variable OF.output after execution?CASE input OF 1: output := 'One'; 2: output := 'Two'; 3: output := 'Three'; ELSE output := 'Other'; END_CASE;
input is 2?2: output := 'Two';.CASE status OF 0: action := 'Stop'; 1: action := 'Start'; 2 action := 'Pause'; ELSE action := 'Unknown'; END_CASE;
2: action := 'Pause';.Pass the test and this pattern moves unknown