IF-THEN statement examples

Richard, can you provide an example of how to use the new IF-THEN capability ( XX ? YY : ZZ)? I’m not clear how to use this within the boundaries of the Conditions fields.

This is a very common programming construct … See:
[url=http://en.wikipedia.org/wiki/%3F:]http://en.wikipedia.org/wiki/%3F:[/url]

In all cases the result is assigned a value.

Given Boolean Values (Or expressions) B1 … BN
And Values (Or expressions) V1 … VN of the appropriate type for condition XX
The condition expression:
XX B1 ? V1 : V2
Can be described in pseudo code as:

    if (B1) {
       XX = V1
    } else {
       XX = V2
    }

[hr]
The condition expression:
XX B1 ? V1 : B2 ? V2 : V3
Can be described in pseudo code as:

  if (B1) {
    XX = V1
  } else if (B2) {
    XX = V2
  } else {
    XX = V3
  } 

[hr]
The condition expression:
XX B1 ? (B2 ? V1 : V2) : (B3 ? V3 : V4)
Can be described in pseudo code as:

  if (B1) {
    if (B2) {
       XX = V1
    } else {
       XX = V2
    } 
  } else 
    if (B3) {
       XX = V3
    } else {
       XX = V4
    } 
  } 

For better or for worse, years of BASIC, PASCAL, and C programming back in my youth have ingrained the IF-THEN logic into my brain.

Within the realm of PLEG, I have assumed that Conditions are either true or false, and an Action results when a Condition is true. This IF-THEN appears to change that, so now conditions can have non-Boolean values. But it doesn’t appear that you can trigger actions directly based on these non-Boolean values.

Is the philosophy here that the IF-THEN statement is used in an intermediate Condition (which won’t trigger any Actions), and then subsequent true-false Conditions test the value of the intermediate condition and then launch an Action? Basically turning the Condition into a variable that can be used in subsequent logic. If so, can I use this to pass strings (perhaps to Vera Alerts)?

I guess my brain just isn’t comprehending the benefit of this yet. I haven’t been able to figure out a way to use the IF-THEN that can’t already be done with several conditions. I’m sure these scenarios exist, I’m just not able to think of one. So I was hoping you could give an actual example within the constraints of PLEG so I can see where it makes sense to use it and how.

The values of Condition Expressions can be used in subsequent conditions as well as arguments to Actions.

I will put out some examples later.

I just noticed that you had added a conditional IF in v4.1 d’oh, I missed it totally.

Is it possible for you to publish an example as I’m not clear as to the syntax.

XX ? YY : ZZ