ELSE IF or not ;)


#1

This is not a piston problem but rather a question about ELSE IF.

My understanding is ELSE IF works kind of different in webcore then ELSE we know in coding (i’m not a coder but it was a hobby in college for awhile)

I have over 100 active pistons and a very complex house but never needed ELSE IF.
What would be an example usage of ELSE IF that can’t be achieved in any other way???

Thank you all for your help.
Ike


#3

I had the same question. I found the post from @Mike1616 helpful. See Post #13


#4

I understand the logic, but does anyone have examples of where they used ELSE IF? I think if I saw some applications of the logic I may see where I could have or should have used.


#5

As far as I am aware there is nothing unusual about ELSE IF in webCoRE. You often see it as ELSIF in other languages. It just saves a lot of nesting. Without it:

IF
THEN
ELSE
    IF
    THEN
    ELSE
        IF
        THEN
        ELSE
        END IF
    END IF
END IF 

With it:

IF
THEN
ELSE IF
THEN
ELSE IF
THEN
ELSE
END IF

Whatever floats your boat really.


#6

There’s usually many different ways we can achieve our goals…


Most of my ELSE IF are ternary operators… such as:

(lt(diff,7) ? '7' : (isBetween(diff,7,14) ? '14' : (isBetween(diff,14,21) ? '21' : (isBetween(diff,21,28) ? '28' : (isBetween(diff,28,35) ? '35' : (gt(diff,35) ? '35' : '42'))))))

Which translates to:

  • IF {diff} is less than 7, then use 7…
  • ELSE IF {diff} is between 7 and 14, then use 14…
  • ELSE IF {diff} is between 14 and 21, then use 21…
  • ELSE IF {diff} is between 21 and 28, then use 28…
  • ELSE IF {diff} is between 28 and 35, then use 35…
  • ELSE IF {diff} is greater than 35, then use 35…
  • ELSE, use 42

In this example, the only time the final ELSE would catch anything is if {diff} was not a number.