|
ColdFusion Home
Basic ColdFusionIntroductionColdFusion Installation ColdFusion Editors ColdFusion Syntax ColdFusion Includes ColdFusion Variables ColdFusion Variable Types ColdFusion If Statements ColdFusion Loops ColdFusion Datasource ColdFusion Database Queries ColdFusion Lists ColdFusion Arrays ColdFusion Redirect ColdFusion Debugging ColdFusion Error Handling Advanced ColdFusionColdFusion MailColdFusion Functions ColdFusion Components ColdFusion Web Services ColdFusion Upload File ColdFusion Read File ColdFusion Write File ColdFusion Append File ColdFusion Rename File ColdFusion Copy File ColdFusion Move File ColdFusion Delete File Cffile Parameters Using cffile Parameters ColdFusion FTP (cfftp) cfftp Cached Connections ColdFusion HTTP (cfhttp) ColdFusion Query of Queries ColdFusion Charts ColdFusion Summary ColdFusion AdminCF AdministratorCF Archive and Deploy CF Scheduled Tasks CF Mini Tutorial ColdFusion BooksColdFusion MX BibleMacromedia ColdFusion MX 7 Web Application Construction Kit FREE Hosting!With every domain name you register with ZappyHost, you get FREE hosting.$1.99 Domain NamesWith every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99. |
ColdFusion Loops (cfloop)A ColdFusion loop is a block of code that executes continuously either a secified number of times, once for each element in an object, or while a condition is true. In ColdFusion, you use the cfloop tag to perform a loop. The cfloop tag has a number of different attributes. The attributes used depends on the type of loop you're performing. Syntax
The Index LoopAn index loop is a loop that continues for a specified number of times. You use the from and to attributes to specify how many iterations should occur. The index attribute holds the counter - it starts with the value of the to attribute and is incremented for each iteration of the loop (until it reaches the value of the from attribute). ColdFusion code:
Display in browser:
1
The (optional) step attribute allows you to determine how big the increments will be. ColdFusion code:
Display in browser:
1
The Conditional LoopA conditional loop is a loop that executes while a condition is true. You use the condition attribute to specify the condtion to use. The following example uses a variable to determine whether to reiterate the loop or not. If the value of the variable is equal to false, the loop will continue to iterate. If it is set to true, it will exit the loop and continue the rest of the code. In this example, we use ColdFusion's RandRange() function to pick a random number between 1 and 10. If the number is 10, the myVar variable is set to true. ColdFusion code:
Display in browser: Tip: Refresh this page a few times and you should see the number of lines change (due to a different random number being generated within the loop).
myVar = false (still in loop)
The Query LoopYou can loop over the results of a ColdFusion query (i.e. using the cfquery tag). Don't worry - if you don't know what I mean by that, we will be learning about ColdFusion queries soon. ColdFusion code:
Display in browser:
Borat
The List LoopYou can loop over a list. You can use the (optional) "delimter" attribute to specify which characters are used as separators in the list.
Display in browser:
ColdFusion
The File LoopYou can loop over a file. To do this, you use the same attributes as you would for a list.
COM Collection/Structure LoopsYou can loop over a Structure or COM collection.
Display in browser:
HTML: HTML Visual QuickStart
Enjoy this website?
Oh, and thank you for supporting Quackit! |
Need Content for your Website?Get unique, quality digital content for your website. You can even earn money by reselling it!Includes:
|