Jump to content

Running Program Terminates if Condition State Changes?


Recommended Posts



I have an IOLinc tied to my garage door and have written a program to trigger the garage fluorescents on, wait a predefined time, then turn the fluorescents off - this occurs any time the IOLinc sensor is switched off (i.e. the garage door is opened).


If I combine all of this within a single program (detection, on, wait, off) and the garage door is opened and closed before the wait period ends, the garage fluroescents stay on indefinitely (i.e. the program never reaches the turn off line after the wait). However, if I break this apart into (2) separate programs and do the garage door sensor detection in one program and the timer (fluorescents on, wait, fluorescents off) in a separate program - then trigger the on/wait/off timer from the 1st detection program, things appear to operate correctly. The lights turn on and turn off even if the garage door is open and closed before the "wait" time frame.


So my question...if the condition of a program evaluates as true and the condition then evaluates as false while the "then" statement is still running (i.e. during a "wait" statement), is the program terminated before completion?


Any assistance in understanding this would be greatly appreciated!

Link to comment

Got it. Thanks for the quick reply!


I also found related info buried in the wiki pertaining to Statement Execution Order...




"Statement Execution Order

Within the Then or Else clause of a program, statements are executed from top to bottom in the order in which they occur. When a statement calls another program, the called program begins executing, and the calling program immediately continues execution with the next statement in sequence--it does not wait for the called program to complete before continuing.

A series of statements within a Then clause (or within an Else clause), up to the next Wait or Repeat statement, are atomic. In other words, all such statements are executed before the conditions of the program are retested. The program's conditions are reevaluated each time a Wait or Repeat statement is encountered, and at the end of each iteration of a Repeat loop.

What this means is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or theThen clause).

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated."

Link to comment

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated."[/size][/font][/color]

I've long suspected this, and make use of it in many places. Good to see its supposed to work this way!

Link to comment


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

  • Create New...