SCL - IF, ELSIF and nesting IF

BoSChoW

Member
Join Date
Apr 2006
Location
Nova Gorica
Posts
107
Hi all, i am a little confused during the past days about the IF statement, ELSIF statement and about the nesting IF statement. I talked to some people and they said one thing about the IF claues while the other people said the other things. About the usage and so on... so i wanted to know what do you thing about the usage of IF statements. Can anyone explain me the difference between the three IFs, the use of each one with some examples please.

Thank you very much for your time and help
Regards
BoSCHoW
 
Could you repeat here the two conflicting descriptions - maybe you could also post the code that led to the confusion?
 
IF is the general command. A typical example would be IF this happens THEN do something.

Many times an IF statement is followed by a choice as in IF the traffic light is red THEN Stop or IF the traffic light is yellow THEN go like hell.

To save lines of code writing some controllers have the ELSEIF command to give a choice. IT effectively puts two commands into one. Like IF the light is green THEN go ELSEIF the light is red THEN stop.

Sooner or later you want the choices to stop and the process to continue so you would use the ENDIF command.

One example:
IF light is red THEN Stop
ELSEIF light is green THEN continue
ELSEIF light is yellow THEN slow down
ENDIF
 
Just for completeness, I've added the final ELSE that you can use to Jim's excellent example.

Jim Dungar said:
IF light is red THEN Stop
ELSEIF light is green THEN continue
ELSEIF light is yellow THEN slow down
ELSE
light is broken
ENDIF
 
L D[AR2 said:
Just for completeness, I've added the final ELSE that you can use to Jim's excellent example.

Thanks,

The light must have been yellow, because I rushed my answer.
 
Thx Jim, well here is some of my code, just to explain what was i thinking.

IF and ELSIF example ??? plc correct me if it is wrong

IF (plc_v1<>op7_v1) OR op7_i1=0 AND (zak.zac_vre=0) AND (zak.kon_vre=0)

//if the value of the plc inputs (plc_v1) is different then the value of the selected inputs on OP7 (op7_v1) or the value of selectd outputs on OP7 (op7_i1) is equal zero and if the analog tolerance (zak.zac_vre "value from" zak.kon_vre "value to") - means that nothing is selected on OP7

THEN vno_prog_stop:=true;

// then the error is displayed on the OP7, and the application is stopped

ELSIF (plc_v1=op7_v1) AND op7_i1<>0 AND (zak.zac_vre=0)OR (zak_kon_vre=0);

// if the value of plc inputs (plc_v1) corresponds to the value of inputs selected on the OP7 (op7_v1) and the value of outputs selected on the OP7 (op7_i1) is different from 0 and if tollerance is equal zero - means that we are useing just DI and DO

THEN set:=true; set2:=true;

// then two timers are started

ELSIF (plv_v1<>op7_v1) AND op7_il=0 AND (zak.zac_vre1>0) AND (zak.kon_vre1>0) AND (zak.zac_vre<zak.kon_vre)

//if the value of the plc inputs (plc_v1) is different then the value of the selected inputs on OP7 (op7_v1) or the value of selectd outputs on OP7 (op7_i1) is equal zero and if tolerance is different from zero - means that we are useing just analog inputs and outputs

THEN set:=true; set2:=true;

// then two timers are started and the program goes on

ELSIF (plc_v1=op7_v1) AND op7<>0 AND (zak.zac_vre>0) AND (zak.kon_vre>0) AND (zak.zac_vre<zak.kon_vre)

//if the value of plc inputs (plc_v1) corresponds to the value of inputs selected on the OP7 (op7_v1) and the value of outputs selected on the OP7 (op7_i1) is different from 0 and if the tollerance is different from zero - menas that we are useing both AI and AO and DI and DO

THEN set:=true; set2:=true;

// then two timers are started and the application goes on

END_IF;

nesting IF example; if it is wrong please correct me

IF (plc_v1<>op7_v1) OR op7_i1=0 AND (zak.zac_vre=0) OR (zak.kon_vre=0)
// if plc input value (plc_v1) differs from the value of selected inputs on OP7 (op7_i1) and the analog tolerance value (zak.zac_vre and zak.kon_vre) is equal zero

THEN vno_prog_stop:=true;
// the OP7 show the error on the screen

ELSE
IF ((plc_v1=op7_v1) AND op7_i1<>0) OR (zak.zac_vre>0 and zak.kon_vre>0 AND zak.kon_vre>zak.zac_vre)
// if the plc value of inputs (plc_v1) is equal to the OP7 value of inputs (op7_v1) or the analog tollerance is selected on OP7

THEN set:=true; set2:=true;
// the two timers are started and the application goes on

END_IF;
END_IF;

I wanted to put the third example, but i dont know how to do it, perhaps somebody of you guys knows and might give me an eazy example with ...

Thanks again for your time and help.

Regards
Bostjan.
 
IF light is red THEN Stop
ELSEIF light is green THEN continue
ELSEIF light is yellow THEN slow down

ELSE:
IF you are pedestrian AND light is red, THEN WALK,
IF you are pedestrian AND light is NOT red, THEN WAIT

ENDIF
 

Similar Topics

HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
99
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
577
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
350
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
663
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
517
Back
Top Bottom