No, it's behaving correctly, you've just found one of the edge cases
with a loosely typed language.  That second expression is equivalent
to this one:

(i GT 0) LT 4

the "i GT 0" part evaluates to true.  It's then used in a numeric
context, so it is coerced to the numeric version of true, which is
one.  The result is compared with 4 using the LT operator, and since
one is less than four, the result of the entire expression is true (or
yes).

These types of edge cases are what make loosely typed languages so
dangerous and difficult to debug.  As you saw, that second expression
is happily evaluated, even though there's an extremely good chance
that it's a typo and consequently a bug.  With a strongly typed
language, the compiler would catch the error for you.

cheers,
barneyb

On Wed, 10 Nov 2004 23:56:21 +0000, Andy Jarrett <[EMAIL PROTECTED]> wrote:
> Came across a weird one (or so i think)
> 
> <cfset i = 5>
> <cfoutput>#i GT 0 AND i LT 4#</cfoutput>
> Returns NO - expected
> 
> <cfset i = 5>
> <cfoutput>#i GT 0 LT 4#</cfoutput>
> Return Yes - not expected
> 
> With the second snippet surely this should error??
> 
> Andy
> www.andyjarrett.co.uk
> 

-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/blog/

I currently have 0 GMail invites for the taking

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:183930
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to