Tutorial by Examples

<!--- Define collection ---> <cfset attributes = { "name": "Sales", "type": "text", "value": "Connection" }> <!--- cfloop tag with attribute collection can be used to loop through the elements of a struc...
<cfscript> /*define collection*/ attributes = { "name": "Sales", "type": "text", "value": "Connection" }; for(attribute in attributes){ /* attribute variable will contain the key name of each key value ...
Parameters AttributeRequiredTypeDefaultDescriptionindextruestringVariable name for the loop's index. Defaults to the variables scope.fromtruenumericStarting value for the index.totruenumericEnding value for the index.stepfalsenumeric1Value by which to increase or decrease the index per iteration.Ba...
Tag syntax Parameters AttributeRequiredTypeDefaultDescriptionconditiontruestringCondition that manages the loop. Cannot contain math symbols like <, > or =. Must use ColdFusion text implementations like less than, lt, greater than, gt, equals or eq. Final value of x is 5. <cfset x = 0 /...
Example for date or time range.
Consider the table dbo.state_zip, which contains the columns city, statecode and zipcode and has over 80,000 records. Parameters AttributeRequiredTypeDefaultDescriptionquerytruestringThe variable name of a query object.startrowfalsenumericThe starting row index of the query object.endrowfalsenumer...
Consider this list: <cfset foo = "one,two,three,four" /> Tag syntax Parameters AttributeRequiredDefaultDescriptionlisttrueA list object. The variable must be evaluated (wrapped with ##)indextrueThe current element of the list. <cfoutput> <cfloop list="#foo#&...
The ability to directly use an array object with cfloop was added in ColdFusion 8. Consider this array; <cfset aFoo = [ "one" , "two" , "three" , "four" ] /> Tag syntax ColdFusion 8 through current Using the attribute inde...
<cfloop list="#myFile#" index="FileItem" delimiters="#chr(10)##chr(13)#"> <cfoutput> #FileItem#<br /> </cfoutput> </cfloop>
Consider this structure: <cfset stFoo = { a = "one" , b = "two" , c = "three" , d = "foue" } /> Tag syntax Parameters Notice the use of the attribute item instead of index. AttributeRequiredTypeDefaultDescriptioncollection...
Use the from and to attributes to specify how many iterations should occur. The (optional) step attribute allows you to determine how big the increments will be. <cfloop from="1" to="10" index="i" step="2"> <cfoutput> #i#<br />...
You use the condition attribute to specify the condition to use. <cfset myVar=false> <cfloop condition="myVar eq false"> <cfoutput> myVar = <b>#myVar#</b> (still in loop)<br /> </cfoutput> <cfif RandRange(1,10) eq 10> ...
You can loop over the results of a ColdFusion query. <cfquery name="getMovies" datasource="Entertainment"> select top 4 movieName from Movies </cfquery> <cfloop query="getMovies"> #movieName# </cfloop>
You can use the (optional) delimiters attribute to specify which characters are used as separators in the list. <cfloop list="ColdFusion,HTML;XML" index="ListItem" delimiters=",;"> <cfoutput> #ListItem#<br /> </cfoutput> <...
You can loop over a file. <cfloop file="#myFile#" index="line"> <cfoutput> #line#<br /> </cfoutput> </cfloop>
You can loop over a Structure or COM collection. <cfset myBooks = StructNew()> <cfset myVariable = StructInsert(myBooks,"ColdFusion","ColdFusion MX Bible")> <cfset myVariable = StructInsert(myBooks,"HTML","HTML Visual QuickStart")> <cf...

Page 1 of 1