Understanding IF statements

Hi,
I know my questions are relatively elementary and have been partly covered in old topics, but I am having trouble making progress. I need multiple input conditions and multiple output actions

Re compound IF/THEN. I take it that the BLOCK IF / ENDIF function is not available? (used by Johnson Control Basic). I am doing som basic tests using several toggle switches for inputs and output monitor blue LEDs.

The poorly formatted example in the T3000 manual (p176) shows conditional branching to different line numbers, with each branch having an END statement. This allows only one scan through the code. (END statements are not recommended so why are they included in an example?).
How would this example look if END was replaced by ???
My main question is how to get the THEN branch to skip over the following ELSE branch. Unless it skips, then both THEN and ELSE branches execute.

I have tried the following:(using local variable A per previous topic). This is a very simple example for test purposes. The desired result is if both inouts are true outputs 1 and 2 both turn on, otherwise outputs 1 & 2 are off and Output 5 is on.

10 IF IN1 AND IN2 THEN A = 1 ELSE 40
20 IF A = 1 THEN OUT1 = 1
30 IF A = 1 THEN OUT2 = 1
40 OUT5 = 1

If both input conditions are true, both outputs 1 & 2 turn on.- OK
If I then turn off either input, line40 executes (OUT5 comes on) but line30 does not execute (OUT2 also stays on)
If I then make both input conditions true again, line 40 still executes and OUT5 remains on

I can get the correct operation using the (inefficient) code:

10 IF IN1 = 1 AND IN2 = 1 THEN A = 1 ELSE A = 0
20 IF A = 1 THEN OUT1 = 1 , OUT2 = 1 ELSE OUT1 = 0 , OUT2 = 0
30 IF A = 0 THEN OUT5 = 1 ELSE OUT5 =0

I seem to have to explicitly reset Outputs if the turn-on logic is not true.

What am I doing wrong here?

IF IN1 AND IN2 THEN START OUT1 , START OUT2
IF NOT IN1 OR NOT IN2 THEN STOP OUT1 , STOP OUT2
IF NOT IN1 OR NOT IN2 THEN START OUT5 ELSE STOP OUT5

Another way would be to create a global VAR which the logic acts upon, then use that VAR to operate on the outputs. I prefer this way since you can place the global var on the screens and trened logs for debugging. Also it keeps things clear having the ‘mode’ logic separate from the ‘output’ logic.

*** Code for the Mode, stored in the global LEDMODE variable ****
IF IN1 AND IN2 THEN LEDMODE = TRUE
IF NOT IN1 OR NOT IN2 THEN LEDMODE = FALSE
*** Code for the outputs ***
IF LEDMODE THE START LED1 AND START LED2
IF NOT LEDMODE THEN STOP LED1 AND STOP LED2
IF NOT LEDMODE THEN START LED5 ELSE STOP LED5

1 Like