Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple conditional question

Explorer ,
Apr 08, 2011 Apr 08, 2011

Many times I got confuse when it comes to using cfif and cfelse.

When I only need to compare 1 variable, it is very clear. If VariableA is blank, count else do not count. Else in here clearly indicates if VariableA is NOT blank.

But in situation such as the following, I'm not sure what cfelse refering to:

<CFLOOP query="MyQuery">

  <!--- In cases where either one of VariableA.B or C is Blank/Doesn't have value --->

   <CFIF (#Len(VariableA)# EQ 0) OR (#Len(VariableB)# EQ 0) OR (#Len(VariableC)# EQ 0)>

     .......

   <CFELSE>

     ......

   </CFIF>

</CFLOOP>

What I want in CFELSE above is, either VariableA AND B AND C can NOT be blank

So, Is the CFELSE here means : A1.  (#Len(VariableA)# NEQ 0) OR  (#Len(VariableB)# NEQ 0) OR  (#Len(VariableC)# NEQ 0) or

                                                 A2.  (#Len(VariableA)# NEQ 0) AND  (#Len(VariableB)# NEQ 0) AND  (#Len(VariableC)# NEQ 0)

TOPICS
Getting started
639
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2011 Apr 08, 2011

First of all, you do not need all those hash|pound|number|octothorpe|# symbols.  You only need those when you want to render the value of a variable into string output.

Secondly, using OR's mean that the true clause will be used if any one or more of the variables have a length.  Using AND's mean that the true clause will be used only if ALL the varaibles have a length.

Of course, this means that the false (aka ELSE) clause will be the oposite in each case.  With the OR's, that means the ELSE will only be used if ALL the variables have no length.  With the AND's, the ELSE clause will be used if any one or more of the variables has no length.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2011 Apr 08, 2011

In addition to the other answer, I think you are processing your logic in the wrong order.  I would test that at least one of them had a value before checking to see if one of them was blank.

One way to do that is to add the lengths to each other.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2011 Apr 08, 2011

VariableA is for City, B is for State and C is for ZipCode

Another variable I did not mention in here is ForeignCityZip, which I use to deffirentiate between US and Foreign location

So my logic goes like this:

If ForeignCityZip is blank,

    This is US location and US location need City,State and ZipCode

       If either one of this column is blank, error out !

         So this is the reason why I use:

           <CFIF Len(VariableA) EQ 0 OR Len(VariableB) EQ 0 or Len(VariableC) EQ 0>

                  .....

           <CFELSE>

           In here I need : City and state and Zip all need to have values so I can use this valid data

           for further coding       

                 -----

          </CFIF>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2011 Apr 08, 2011

I would turn the logic around.

<CFIF Len(VariableA) NEQ 0 AND Len(VariableB) NEQ 0 AND Len(VariableC) NEQ 0>

    <!--- ALL THE VARIABLES HAVE VALUES, process them --->

<CFELSE>

   <!--- One or more of the variables DO NOT have values, throw the error --->

</CFIF>

Message was edited by: ilssac  EDITED to add the NOT EQUAL operator required for this version of the Boolean logic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2011 Apr 08, 2011
LATEST

I see

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources