Change condition dynamically


I wonder if some of you have figured out a way to change a condition dynamically.
For instance, for the following condition statement,
/*** existing variable condition expressions: condi1, condi2
potential variable: condiTran ( a transient variable OR optional condition evaluation, just for condi3 )
condiTran default value of 1=1
potential variable: condi3

Thus, condi3 variable expression becomes available, for instance, “rain is true” ( of which “rain” is a variable )
Then, the following code:

<cfif condi1 AND condi2 AND condiTran>
   do this or that 

would be executed as:

<cfif condi1 AND condi2 AND rain is true>
   do this or that


<cfif condi1 AND condi2 AND 1=1>
   do this or that

The thought was, 1=1 is always true, thus AND 1=1 should work but not. Thoughts?

in cfml, conditional logic does short circuit evaluation, 1=1 will only be evaluated if cond1i and condi2 are true

otherwise the following would error, if doesn’t exist

<cfif structKeyExists(url,"name") and eq "lucee">

Interesting. The following works.

<cfif structKeyExists(url,"name") and IS "lucee" AND 1=1>
	then do this.

	DV = "1=1";

<cfif structKeyExists(url,"param2")>
	<cfset DV = "bought2.price gt 3">
	<!--- OR 
	<cfset DV = "bought2.price gt 9">

<cfdump var="#DV#">

<cfif p7 gt bought2.price AND DV>
	do that

However, I have a very similar bunch of code, it bombed out, err msg:

Can’t cast String [(1 = 1)] to a boolean

should be

<cfset DV = bought2.price gt 3>
<cfset DV = (bought2.price gt 3)>

the brackets just make it a bit clearer that it will be evaluated

1 Like

Yeah, great observation.