Created
March 24, 2014 23:21
CFLoop Attributes Evaluated Only Once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfoutput> | |
<!--- Create an initial array of items. ---> | |
<cfset arrItems = ListToArray( "ben,dave,mark,mike" ) /> | |
Original Length: #ArrayLen( arrItems )#<br /> | |
<br /> | |
<!--- | |
Loop over the items in the array. For each iteration, add | |
an item to the array to see if the loop will keep going. | |
In the TO attribute, use the Min() method to ensure that | |
the loop doesn't go on infinitely. | |
---> | |
<cfloop | |
index="intIndex" | |
from="1" | |
to="#Min( 10, ArrayLen( arrItems) )#" | |
step="1"> | |
<!--- Output the iteration values. ---> | |
Iteration #intIndex#. Array Length: #ArrayLen( arrItems )#<br /> | |
<!--- Add an Item to the array to see if we keep looping. ---> | |
<cfset ArrayAppend( | |
arrItems, | |
"sarah" | |
) /> | |
</cfloop> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment