Contact Us

 Bharat Patel     Feb,08 2017

CFLOOP[Index, Collection, List, Query] in CFSCRIPT

CFScript is a language in language. It is scripting language. We can write a code similar to JavaScript. It runs on the ColdFusion server. it does not run on the client system. We can use all coldfusion function and variables that are available in script's scope.

We can not use cfloop [Index,List,Collection,query] inside cfscript. Today, I have done how to use loop [Index,List,Collection,Query] in cfscript. I hope it may be helpful.

<!--- Index Loop ---><cfscript>writeOutput('<h3>Index Loop</h3><br />');for(i=0; i<10; i++) {writeOutput("Loop index is : #i# <br /> ");}</cfscript><!--- Collection Loop ---><cfscript>testStru = structNew();testStru.firstname = "Bharat";testStru.lastname = "Patel";writeOutput('<h3>Collection Loop</h3><br />');for(i in testStru) {writeOutput("#i#[<b>#testStru[i]#</b>]<br>");}</cfscript><!--- List Loop ---><cfscript>TestList = 'Bharat,Pritesh,Naresh,Akash,Nirav';writeOutput('<h3>List Loop</h3><br />');for(i=1;i<=ListLen(TestList);i++){value = ListGetAt(TestList,i);writeOutPut('#value#<br />');}</cfscript><!--- Query Loop ---><cfquery name="qArt" datasource="cfartgallery">SELECT *FROM ArtistsWHERE 1 = 1</cfquery><cfscript>writeOutput('<h3>Query Loop</h3><br />');for(i=1;i<=qArt.recordCount;i++){writeOutput('<b>ArtistId</b> : '& qArt[ 'ArtistId' ][ i ]& ' <b>FirstName</b> : ' & qArt.Firstname[i]& ' <b>LastName</b> : ' & qArt['Lastname'][i]& '<br />');}</cfscript>