ColdFusion Programming/control structures

As in most programming languages Coldfusion includes control structures to help your program be more useful.

CFIF
The most basic control structure is the CFIF. It works exactly like an If statement in other programming languages.

A sample CFIF statement would look like this: First Second

The result would be: First

CFSWITCH
Like with other programming languages Coldfusion provides a switch functionality.

Sample CFSWITCH: George Bob

The result would be: Bob

CFLOOP
Index Loop:
 * Attributes
 * from - starting number
 * to - ending number
 * index - value within the loop
 * step - optional (default 1) - change to make with each iteration

Example:  #i#

Results: 1 2 3 4 5 6 7 8 9

 #i#

Results: 1 3 5 7 9

Conditional Loop:
 * Attributes
 * condition - continue looping as long as condition is true

Example: #i# 

Results: 1 3 5 7 9

Query Loop:
 * Attributes
 * query - query name you want to loop through
 * startrow - optional(default 1) - row to begin with
 * endrow - optional(default last) - row to end with

Query getpeople looks like this: Age Name 10 Bill 25 Martha 30 Judy

Example: #Age#, #Name#

Results: 10, Bill 25, Martha 30, Judy

List Loop:


 * Attributes
 * index - variable to hold element of list
 * list - list to go through
 * delimiters - optional (default ,) - separator used to break list apart

List people looks like this: (Bill,Martha,Judy)

Example:  #i#!

Results: Bill! Martha! Judy!

Collection Loop:
 * Attributes
 * collection - structure name you want to loop through
 * item - variable to hold element of structure

Structure place looks like this: Zip  Name 55057 Northfield

Example:  #i#-#place[i]# ,

Results: Zip-55057, Name-Northfield