blueman2 Posted November 9, 2018 Posted November 9, 2018 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?
paulbates Posted November 9, 2018 Posted November 9, 2018 (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 November 9, 2018 by paulbates 1
blueman2 Posted November 9, 2018 Author Posted November 9, 2018 That is what I thought. Yes, I usually run another program 'then' segment to ensure follow through but wanted to confirm. Thanks, Paul!!
larryllix Posted November 9, 2018 Posted November 9, 2018 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.
kclenden Posted November 10, 2018 Posted November 10, 2018 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.
larryllix Posted November 10, 2018 Posted November 10, 2018 (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 November 10, 2018 by larryllix
kclenden Posted November 10, 2018 Posted November 10, 2018 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. 1
apostolakisl Posted November 11, 2018 Posted November 11, 2018 (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 November 11, 2018 by apostolakisl 1
larryllix Posted November 11, 2018 Posted November 11, 2018 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
Recommended Posts