Change condition dynamically

Hi,

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 
</cfif>

would be executed as:

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

ELSE

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

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 url.name doesn’t exist

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

Interesting. The following works.

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

<cfscript>
	p7=7;
	bought2.price=8;
	DV = "1=1";
</cfscript>

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

<cfdump var="#DV#">

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

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>
or 
<cfset DV = (bought2.price gt 3)>

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

1 Like

Yeah, great observation.