Looping through A to Z in ColdFusion
There are always more than single methods to accomplish the same job in programming language. To loop through the letters from A to Z in ColdFusion there are also more than one way, but I personally found out the following 2 methods are simpler and strain forward.
Hardcode the A to Z into a list and just loop over it
<cfloop
index=”strLetter”
list=”A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z”
delimiters=”,”>
<cfdump var=”#strLetter#”>
</cfloop>
The other way to loop through the letters is using the ASCII value from A to Z. We first convert the A and Z to ASCII, than just use the number to loop through the rest and convert it back to char to get back our result.
<cfloop
index=”intLetter”
from=”#Asc( ‘A’ )#”
to=”#Asc( ‘Z’ )#”
step=”1″>
<!— Get character of the given ascii value. —>
<cfset strLetter = Chr( intLetter ) />
<cfdump var=”#strLetter#”>
</cfloop>
Please feel free to share the way you usually use or you may found out any other better way to do the job.