– Common Function Library Project

ListLoop(theList, theEval[, theDelim])

Last updated June 26, 2002


Shawn Seley

Version: 1 | Requires: CF5 | Library: StrLib

Applies the passed evaluation to every element in the specified list. Allows versatile conversions, calculations, formatting and other alterations to an entire list in one easy step. Use the variable "x" in the passed evaluation to denote the current list element.

Return Values:
Returns a string.


<cfset my_list = "one,two,three">
<cfset my_list2 = "1,2,3">
<cfset my_list3 = "This is a test">

#ListLoop(my_list, "x & ""y""")#<br>
#ListLoop(my_list, "Left(x, Len(x)-1)")#<br>
#ListLoop(my_list2, "x*3")#<br>
#ListLoop(my_list2, "NumberFormat(x, ""0.000"")")#<br>
#ListLoop(my_list2, "MonthAsString(x)")#<br>
#ListLoop(my_list3, "Reverse(x)", " ")#<br>


Name Description Required
theList The list to work with. Yes
theEval The evaluation to execute. Yes
theDelim Delimiter to use. Defaults to a comma. No

Full UDF Source:

 * Applies simple evaluations to every element in a list.
 * @param theList 	 The list to work with. (Required)
 * @param theEval 	 The evaluation to execute. (Required)
 * @param theDelim 	 Delimiter to use. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Shawn Seley ( 
 * @version 1, June 26, 2002 
function ListLoop(theList, theEval) {
	var i             = 0;
	var theList_len   = 0;
	var x             = "";

	var theDelim      = ",";
	if(ArrayLen(Arguments) GTE 3) theDelim = Arguments[3];

	theList_len   = ListLen(theList, theDelim);

	for (i=1; i LTE theList_len; i=i+1) {
		x = ListGetAt(theList, i, theDelim);
		theList = ListSetAt(theList, i, Evaluate(theEval), theDelim);

	return theList;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson