>- see footer for list info -<
Well, "how else it could work" is the way that a true switch/case works in
other languages, where the whole point really is that all the switch/case
logic gets turned under the covers into a "computed goto", where once the
expression is determined, it "jumps" to the one (and only one) condition
that it could match. That's why it's always said to be faster than an
equivalent list of IF/ElseIF statements.
And in fact, I do believe that that IS the way CF works. Here's proof. Some
may know that CFCASE can list more than one value. That's handy. But it DOES
NOT open the door to permitting any of multiple cases to be matched. In the
following code:
<cfswitch expression="sam">
<cfcase value="bob">
I'm in bob
</cfcase>
<cfcase value="bob,sam">
I'm in bob or sam
</cfcase>
<cfdefaultcase>
I'm in neither case, the default
</cfdefaultcase>
</cfswitch>
it errors complaining that "The CFSWITCH has a duplicate CFCASE for value
"BOB". That would indicate that indeed, it wants to know there is one and
only one case that could match. And the only reason to do that would be if
it intends to jump to that, and not do a scroll down the list of cases.
Maybe someone with more internals understanding can more categorically state
or prove that it doesn't go down the list of cases. I would think, though,
that the book reference JGG offers was simply a mistake on the author's part
(and there were multiple contributors, so it could have been other than
Ben). JGG, was that the 7 version, or the 6? I see no errata about this in
the 7 version (http://www.forta.com/books/errata.cfm?p=36). I don't see any
link to the older books, so can't check their errata. It could be that it
was caught and corrected in subsequent versions. What section and page (and
version) is that in? I have the 7 edition and can compare it, and report it
to Ben if it's indeed "fresh".
/charlie
http://www.carehart.org/blog/
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Snake
Sent: Monday, August 07, 2006 6:27 AM
To: [EMAIL PROTECTED]; 'Coldfusion Development'
Subject: RE: [CF-Dev] CFSwitch... Aren't all cases evaluated?
>- see footer for list info -<
Yes that is correct, all cases will be evaluated until a match is found, how
else could it work?
But here is a little nugget.
If you are evaluating strings in your cfcases, as you probably are 99% of
the time. CFIF/ELSE is faster.
Russ
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Terry Riley
Sent: 07 August 2006 11:15
To: [email protected]
Subject: Re: [CF-Dev] CFSwitch... Aren't all cases evaluated?
>- see footer for list info -<
----- Original Message -----
> *From:* "Jolly Green Giant" <[EMAIL PROTECTED]>
> *To:* [email protected]
> *Date:* Sun, 6 Aug 2006 23:07:50 -0400
>
> >- see footer for list info -<
> I'm studying for my certification. Forta, in the study book, says
> that "like cfif, you should put the most popular cases at the top of
> the cfswitch block to improve performance.
>
> I thought one of the things was that all the cases were going to be
> evaluated anyway? If they're all evaluated, then their location is no
> performance gain, right?
I don't think they are all evaluated, unless it goes to the default case
(which is usually last). IIRC, evaluation continues until a match is found.
There may be others out there that disagree....
HTH
Terry
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<