• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Working with Loops

There will be times when you need to execute the same piece of code over and over again. For example, you might need to perform frequent mathematical calculations, analyze a list, or repeat a query. This is called looping. A loop does exactly what it sounds like—it loops over a piece of code until a condition is met, or for however long was specified. For example, you could add up the total cost of several products by looping over the values and adding them together, and when that was done, you could end the loop and output the value.

ColdFusion provides a <cfloop> tag to handle all of your looping requirements. You can use <cfloop> to loop over code a certain number of times by specifying “to” and “from” values. For example, you could loop from 1 to 100, causing your loop to execute 100 times. Or you can loop over a list of items. A loop that goes on forever is called an infinite loop, and is not a good thing.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint