7

Im a PLC programmer and I am wondering why the reserved word elsif (ie without the E ) is used. I know that elseif or any other combination is not used as reserved words. Is there a history to use this in other Languages. If so why? just to save on typing cause for me I seem to make the mistake of typing the e probably 5 times a day.

mrebus
  • 111
  • 1
  • 8

3 Answers3

6

Programming languages have never quite agreed on this. Various common languages use:

else if
elseif
elsif
elif

and perhaps others. There's often no good reason for the language designer choosing one over another.

(Bonus points if you can name some languages that use each of the above forms!)

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

I wonder what type of PLC you are programming, I just found out rockwells structured text uses elsif, and Ada did but thats not really for PLCs is it?

I am told it's Syntactic sugar, the elsif is there so you don't have your code cluttered up by lots of brackets

if cond1 then 
   funct1 
elsif cond2 then
   funct2 
elsif cond3 then
   funct3 
else
   funct4 
end if

becomes

if cond1 then
   funct1 
else (if cond2 then
       funct2 
        else (if cond3 then
         funct3 
          else funct4 
))
end if

As far as the origin goes my guess would be it has just stuck around since Ada or whatever was before that.

daniel
  • 471
  • 1
  • 4
  • 13
  • 1
    Yeah I use rockwell I manly make the mistake cause my mind thinks elseif and I just react with an e. – mrebus Sep 26 '11 at 22:24
0

Pascal is the father of Structured Text (or SCL as called by Siemens) used in PLCs.

avra
  • 3,690
  • 19
  • 19