Jump to content

Does 'Then' terminate if program no longer true?


blueman2

Recommended Posts

Posted

Question regarding programming.  I used to know this, but my memory has failed me.  Will a 'Then' segment terminate if a line in the 'Then' segment does that causes the program to no longer be true?  Or will the 'Then' segment complete regardless of the Trueness of the program?  

 

 

Posted (edited)
11 minutes ago, blueman2 said:

Will a 'Then' segment terminate if a line in the 'Then' segment does that causes the program to no longer be true?  

Yes.

Sometimes this works perfectly and you want it. The example is a notification for a door sensor notification. Put a wait, and if the door closes before the wait completes, program stops and no notification

Sometimes is not what you want. The way around this is to "Run" a another program under Then, that can have no "If" clause in the new program and it will run to completion.

Paul

Edited by paulbates
  • Like 1
Posted

That is what I thought.  Yes, I usually run another program 'then' segment to ensure follow through but wanted to confirm.  Thanks, Paul!!

Posted
18 minutes ago, blueman2 said:

That is what I thought.  Yes, I usually run another program 'then' segment to ensure follow through but wanted to confirm.  Thanks, Paul!!

But.....

If the initiating program has another trigger and runs the second program (with or without  If logic lines) whatever is running (Then/Else) will stop and the appropriate section (dependant on the If logic  outcome) will start from the top anyway.

Posted
9 hours ago, larryllix said:

But.....

If the initiating program has another trigger and runs the second program (with or without  If logic lines) whatever is running (Then/Else) will stop and the appropriate section (dependant on the If logic  outcome) will start from the top anyway.

But....

That should only be a problem if the initiating program contains an OR in the IF logic.  If it's a bunch of ANDs then a change in any of the conditions should cause the opposite program section to run (THEN -> ELSE or ELSE -> THEN) and the command that started the second program shouldn't be executed again.

Posted (edited)

The point was a clarification of what PaulBates posted above.
If  Program1 calls program2 while program2 is still running it will start over anyway, so it isn't a complete isolation.

Eg.

Program1
If
      whatever
Then
    Repeat every 2 seconds
        call Program2 (if)
Else
     ------

Program2
If
    whatever
Then
      turn On Light
      Wait 5 seconds
      turn Off Light
Else
    ----

Light will  never turn off. Program1 will start Program2 again every 2 seconds interrupting the Wait 5 seconds, regardless of Program2 logic.

Edited by larryllix
Posted
8 hours ago, larryllix said:

The point was a clarification of what PaulBates posted above.
If  Program1 calls program2 while program2 is still running it will start over anyway, so it isn't a complete isolation.

Eg.

Program1
If
      whatever
Then
    Repeat every 2 seconds
        call Program2 (if)
Else
     ------

Program2
If
    whatever
Then
      turn On Light
      Wait 5 seconds
      turn Off Light
Else
    ----

Light will  never turn off. Program1 will start Program2 again every 2 seconds interrupting the Wait 5 seconds, regardless of Program2 logic.

Your point of clarification was good as most people probably think once a program with no IF conditions starts to run it will eventually complete.  I was only commenting about what I perceived to be the OP's use case.  Something like this:

Program1
If
     A
 and B
Then
	Call Program2 (Then)
Else

Program2
If
Then
	Turn On Light
	Wait 60 Seconds
	Turn Off Light
Else

In this case, while Program2 isn't really completely isolated from Program1, it is effectively isolated since a change in A or B would cause the Else to run not the THEN.  But...

Program1
If
 (    A
 and B)
  or C
Then
	Call Program2 (Then)
Else

Program2
If
Then
	Turn On Light
	Wait 60 Seconds
	Turn Off Light
Else

In this case Program2 really isn't isolated from Program1 since either "(A and B)" or "C" could have originally caused the THEN to run such that a change in either "C" or "(A and B)", respectively, could cause the THEN to run again which would restart Program2.

  • Like 1
Posted (edited)

To sum this up.

Then/Else clauses are ATOMIC.  

Basically, that means they are indivisible (based on the original understanding of an atom as being non-divisible and hence named atomic after the Greek word for indivisible.).  So, once a "then" or "else" starts, it finishes.  The exception to this is a "wait" or "repeat" which creates multiple "atoms" within the "then" or "else".  So it only will finish the current "atom" should the program be re-triggered.

Edited by apostolakisl
  • Like 1
Posted

To add to that, for people with  <Win 2K coding experience, the ISY Wait and Repeat are like inserting a voluntary "give up your time slice to the o/s".
Early windows apps required the code writer to do regular "releases" of their time slice to make the multitasking function work since Windows wasn't a "real" multitasking o/s.

In VB it was
   dummy = DoEvents()

In C++
  sleep 0

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37.2k
    • Total Posts
      372.6k
×
×
  • Create New...