Depending on deployment and expected usage, I would suggest adding an 'if' statement around the loop to Dale's code in order to check if the arguments.value is greater than 32. This will reduce the 'if' statement inside the loop to only 1 value check, allowing for a cfbreak to be added as an 'else' statement.
<cfif arguments.value gt local.return> <cfloop index="local.index" list="#arguments.list#"> <cfif local.index lt arguments.value> <cfset local.return = local.index /> <cfelse> <cfbreak> </cfif> </cfloop> </cfif> This will allow the function to not perform the loop in the case of the default value of local.return being the only 'true' value to return. It will also allow the loop to stop running the moment a 'true' value is found. In a small deployment, this won't mean a thing, but in a large scale deployment anticipating a lot of use, the milliseconds saved can be valuable. Just my 2 cents William -- William E. Seiter Have you ever read a book that changed your life? Go to: www.winninginthemargins.com Enter passkey: goldengrove -----Original Message----- From: Dale Fraser [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 02, 2007 10:09 PM To: CF-Talk Subject: RE: Next lowest number from array (or list). <cfset myList = "32,48,64,72,144,160,200,288,320,400,512,576,640,720,800"> <cfoutput>#getNextLowest(myList, 12)#</cfoutput> <cffunction name="getNextLowest" returntype="numeric"> <cfargument name="list" type="string" required="true" /> <cfargument name="value" type="numeric" required="true" /> <cfset local = structNew() /> <cfset local.return = 32 /> <cfloop index="local.index" list="#arguments.list#"> <cfif local.index lt arguments.value and local.index gt local.return> <cfset local.return = local.index /> </cfif> </cfloop> <cfreturn local.return /> </cffunction> Regards Dale Fraser http://learncf.com -----Original Message----- From: Andy Matthews [mailto:[EMAIL PROTECTED] Sent: Wednesday, 3 October 2007 3:20 PM To: CF-Talk Subject: Next lowest number from array (or list). Say that I have a list of allowed nmbers: 32,48,64,72,144,160,200,288,320,400,512,576,640,720,800 If I give the user the option of selecting a number, and it happens to not be in this list, how might I go about automagically selecting the next lowest number? One exception being if the user selects a number lower than 32, in which case the code should return 32. Examples: User selects 100, the code would return 72. User selects 480, the code would return 400. User selects 25, the code would return 32. Currently the numbers are stored in a simple list, but I have control over that list and they can be in whatever format makes the most sense. One caveat is that they need to stay in code (so no database interaction). ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Get involved in the latest ColdFusion discussions, product development sharing, and articles on the Adobe Labs wiki. http://labs/adobe.com/wiki/index.php/ColdFusion_8 Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290043 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4