And if you expect your list to ever be shorter than your desired subset, you
could dynamically set your "to" attribute using the iif function so you
don't error out:

<cfset variables.list = "0,1,2,3,4,5,6,7">

<cfloop from="1" to="#iif(listlen(variables.list) gt 3, DE('3'),
'listlen(variables.list)')" index="i">
        <cfoutput>#listgetat(variables.list,i)#</cfoutput><br>
</cfloop>

Although that might be overkill for your situation. You will probably want
to verify my syntax as well, it's probably wrong.

Adam.



> -----Original Message-----
> From: Craig Dudley [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 05, 2002 9:22 AM
> To: CF-Talk
> Subject: RE: Easy way to loop over first x items of long list
> 
> 
> <cfset variables.list = "0,1,2,3,4,5,6,7">
> 
> <cfloop from="1" to="3" index="i">
>       <cfoutput>#listgetat(variables.list,i)#</cfoutput><br>
> </cfloop>
> 
> -----Original Message-----
> From: Paul Sinclair [mailto:[EMAIL PROTECTED]]
> Sent: 05 February 2002 15:16
> To: CF-Talk
> Subject: Easy way to loop over first x items of long list
> 
> 
> If I have a list of 10 items or so (0,1,2,3,4,5,6,7,8,9) and want to
> loop over just the first 3 items (for example), what's the 
> easiest way?
> I can't find a List function that selects just the first x items of a
> list. I can use ListGetAt to select the 1st one, then the 
> 2nd, then the
> 3rd, but if I wanted to loop through a large number of items in a long
> list, that gets tedious.
> 
> I guess there is probably some List function that does this 
> that I have
> just overlooked?
> 
> Thanks,
> Paul
> 
> 
______________________________________________________________________
Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to