Jump to content

Else statement ?s


jgorm

Recommended Posts

Does the else statement always run all the time, or does it only run if the "if' statement has an "and" statement and it is not true. For example

If motion 1 is on

and time between 6 and 7

The run -whatever

Else - run whatever 2

 

If the motion is triggered, but the time is not between 6 and 7, will it run the else? Or does the Else run any time that the motion is off?

 

I'm trying to see if I can cut down my programs using this technique.

Link to comment

Compound If statements are not required for the Else clause to execute. A simple single If statement can cause the Else to executed.

 

Neither the Then nor Else clause run all the time. Something in the If section causes the Program to be triggered. For example, If Status 'xxxxx' is On. When the Status of 'xxxxx' changes the Program is triggered (executed). When the If statement is True, in this case Status is On, the Then clause runs. When the If statement is False, in this case Status is other than On, the Else clause runs. Everything is event driven, Status has to change for the Program to be triggered (executed). Once the Program is triggered the If evaluation determines which clause, Then or Else, is executed.

 

The answer to the specific question, yes, when Motion is triggered outside the time range the Else clause executes because the If is False. Also at the specific From and To times the Program is triggered. The If example is missing either Status or Control so the results of the If, True or False, cannot be accurately stated. At the To time the If will be False because it is later, albeit by milli seconds, past the time range.

Link to comment

Thanks LeeG! You have been a big help and thanks for taking the time to respond to my basic questions!

 

So if I am following you correctly, there is no order to the IF statements. I assumed the first IF statement would have to run first, but it seems that they can trigger in any order and the program will then check the other and statements. Is that correct?

Link to comment

In this sample

 

If Status 'xxxx' is On

And Status 'yyyy' is On

And Status 'zzzz' is On

Then

some action

Else

some action

 

a change in Status of 'xxxx' or 'yyyy' or 'zzzz' with trigger the Program (cause it to execute). The entire If is evaluated when the Program is triggered. When all three devices are On the Then clause runs. When any of the three devices is not On the Else clause runs.

 

Any of the If statements can make the Program run. Note that not every statement that can be placed in the If section will trigger the Program. A test of an Integer variable will affect the True/False evaluation but will not trigger the Program. Once triggered the If is evaluated top down as one would read the If section to evaluate True/False

Link to comment

Cutting through all the confusion, you need to understand one thing.

 

When and only when a program triggers will it either run the true (then) or false (else) clause.

 

If you understand triggers then you will get it.

 

For example

 

status: trigger every time there is change in status of specified device

control: trigger every time the specific action is taken (control switched on) (never evaluates to false unless you use "not", then is always false)

state variable: every time the variable changes

integer variable: never a trigger

time is: triggers at that time (always true, again unless you use "not")

time is from/to: triggers at from and to times (true and false)

You may also force trigger a program from another program or manually by doing a "run xxx".

 

These are the most common triggers, others exist, especially if you have modules.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...