On 5/29/01, Tony Hicks penned:
>When you have a CFIF with a CFELSE or CFELSE IF... does cold fusion only
>read the code inside the matching condition?
>
>For instance
>
><cfif name is 'bob'>
>Name = Bob
><cfelseif name is 'joe'>
>Name = Joe
></cfif>
>
>If the name is 'bob' does CF pay any attention to the content to be
>processed if the name is joe? and if the name is joe, does it pay any
>attention to "bob's content" since it comes first...?

I believe CF starts with the beginning of the cfif and stops 
processing the statement when it hits TRUE.

<cfif name is "Bob">
Bob is here. Hi Bob!
<cfelseif name is "Bob" or name is "Frank">
Frank is here. If Bob was here, we'd have never gotten this far. Hi Frank!
</cfif>

Consequently, when I write a long cfif, cfelseif, cfelseif, cfelseif, 
cfelseif, cfelseif, cfelseif, cfelseif, cfelseif, I try and put the 
expressions that are most likely to hit at the beginning.

Like if your checking if a variable is defined and it's a variable 
that gets defined on the first page and stays defined, I do:

<cfif isdefined('myvariable')>
Do this
<cfelse>
Create the variable or whatever
</cfif>

If it's a variable that is usually not defined but causes something 
to happen when it is:

<cfif not isdefined('myvariable')>
Go about your business
<cfelse>
Do something
</cfif>

To test this I made a little thing:

<cfif myvariable is 1>1
<cfelseif myvariable is 2>2
<cfelseif myvariable is 3>3
<cfelseif myvariable is 4>4
....etc, thru 100

When setting the variable to 1, the first time I loaded the page it 
executed in 150 ms. Reloads are from 0 to 2 ms. Set at 50, the first 
page load is executed in 170 ms and reloads are in 5 to 7 ms. Set at 
100, the first page load is executed in 180 ms and reloads are in 8 
to 10 ms.

Certainly not a huge difference, but when all of a sudden you find a 
page with 1,000 lines of code and cfif, cfelseif all over the place, 
every little bit helps.

And the same test running cfswitch had pretty similar results on the 
initial load, but reloads were always 0 or 1 ms.
-- 

Bud Schneehagen - Tropical Web Creations

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to