使用:=、S=、R=、SEL替代IF…END_IF

IF…END_IF及其嵌套会导致代码量过于庞大,不易阅读和调试。
例1:若只有一个变量,可直接用:=

IF In.Sensor1 THEN
    Out.Cylinder1:=TRUE;
ELSE
    Out.Cylinder1:=FALSE;
END_IF;

可简写为

Out.Cylinder1:=In.Sensor1;

例2:若有两个变量切换,可用S= R=

IF In.Sensor1 THEN
    Out.Cylinder1:=TRUE;
END_IF;
IF In.Sensor2 THEN
    Out.Cylinder1:=FALSE;
END_IF;

可简写为

Out.Cylinder1 S= In.Sensor1;
Out.Cylinder1 R= In.Sensor2;

例3:切换变量值,使用SEL:

IF xEnable THEN
    rSet:=5;
ELSE
    rSet:=0;
END_IF

可简写为

rSet:=SEL(xEnable,0,5);