Skip to main content
November 21, 2008
Question

cfif

  • November 21, 2008
  • 6 replies
  • 654 views
I don't understand the logic here...

<cfif #page_indicator_a# NEQ '1' OR #page_indicator_a# NEQ '2'>

won't work but this will

<cfif #page_indicator_a# NEQ '1'>
<cfif #page_indicator_a# NEQ '2'>


Can someone tell me why!?
This topic has been closed for replies.

6 replies

November 21, 2008
It is clear now what I was doing wrong. OOPS. Thank you for the quick refresher course in boolean logic.

Sometimes when I've been coding all day my brain gets dull if not useless.
tclaremont
Inspiring
November 21, 2008
Thanks Ian, in reading my inital response, it is almost as confusing as the original CFIF statement!
tclaremont
Inspiring
November 21, 2008
There are lots of ways to do this. I took the question as theoretical, and there is most definatley a problem with the theory in the original posters CFIF statement!
Inspiring
November 21, 2008
idesdema wrote:

>
> Can someone tell me why!?
>

As tclaremnot said it is the 'OR'. The if statement will be true if
either side is true. So if the value is 1 then it is NOT 2 and so the
combination is true. If the value is 2 then it is NOT 1 and so the
combination is true. If the value is 3 then both NOT 1 and NOT 2 is
true so it is true.

You have written a statement that can never be false, unless you can
somehow have a value that is both 1 and 2 at the exact same time.

Now that I have my boolean logic lecture out of my system your solutions
is probably either:


<cfif #page_indicator_a# NEQ '1' AND #page_indicator_a# NEQ '2'>

OR

<cfif NOT (#page_indicator_a# EQ '1' OR #page_indicator_a# EQ '2')>
Inspiring
November 21, 2008
Wouldn't it be better if you use cfswitch instead of cfif?
<CFSWITCH expression="#page_indicator_a#">
<CFCASE value="1"> do something here</CFCASE>

<CFCASE value="2"> do something here </CFCASE>

</CFSWITCH>
tclaremont
Inspiring
November 21, 2008
What is your objective? What is the failure mode?

You are asking if the page is not 1 OR if it is not 2. That means if it is 1 it meets the second condition of NOT being 2. This also means that if it is a 2 it meets the first condition of NOT being 1.


Wouldn't it be easier to ask if #page_indicator_a# GT 2? Or
<cfif #page_indicator_a# NEQ '1' AND #page_indicator_a# NEQ '2'>