> Original Message:
> > From: "Barney Boisvert" <[EMAIL PROTECTED]>
> > Actually, I think what's happening is CF is returning the value of the
last
> > evaluated portion of the _expression_.  In the first, both need
evaluation, so
> > we return 3, the second one.  If the second, only the first needs
evaluation
> > (becase we know the _expression_ can't be true if either part is false),
so
> > false is returned.
> >
> > That's just a guess though.
>
> Looks like that was a good guess. I tried swapping it to be #(3 and True)#
and it does display true.
>
> So, that explains what it does.  It sure doesn't explain why. That just
seems retarded. It seems like it should return the boolean result, and not
"whatever was last evaluated".
>

In ColdFusion, doing a boolean evaluation on a non-zero value will return
true. It's been that way for a long time. So, in your original e-mail, you
were mistaken when you thought that CF was multiplying 1*3. In reality, it
was just saying "TRUE is true" and "3 is true" (again, because 3 is a
non-zero value). This is why you can use the following code:

<cfif myQuery.recordCount>
<!--- This will run if there is at least one record --->
</cfif>

Further, in your second example that evaluates to false, ColdFusion uses
short-circuit boolean evaluation, meaning that if the first part of the
statement is false, then it won't even look at the second part of the
statement (it wasn't always like that).

Of course, you could argue the clarity of non-zero values evaluating to
true, but I think that's the way it works in most other languages as well.

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to