Question

Is there any difference in how these two conditional statements will be evaluated?

<cfif Catalog_Id eq 123 or Catalog_Id eq 456 and CatalogType eq 1></cfif>
<cfif (Catalog_Id eq 123 or Catalog_Id eq 456) and CatalogType eq 1></cfif>

From what I recall, the conditional statement will be evaluated from left to right. That means that the OR statement will be evaluated and then the AND condition will be evaluated.

In this case are the parentheses necessary or are they just for readability? Will the be evaluated in all languages in the same order?

UPDATE

For some reason, I couldn't wrap my tired brain around the concept of how this was executing. As soon as someone pointed out the obvious, I woke up and wondered how I hadn't been able to figure out the answer myself. Ugh.

Was it helpful?

Solution

The first statement is evaluated as Catalog_Id eq 123 OR (Catalog_Id eq 456 and CatalogType eq 1)

The second statement is evaluated as (Catalog_Id eq 123 or Catalog_Id eq 456) AND CatalogType eq 1

These are two every different statements. Check out Adobe's Operator precedence and evaluation ordering

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top