Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Variable Scope 1

Status
Not open for further replies.

carpediem79

Technical User
Aug 2, 2005
52
US
Ok....I am having an issue with a page I am creating.

I need to have a bunch of cfqueries repeat. What I need to know is....is it possible to increment the value of a variable, say the variable is "count", which is declared with a value of 1. Say "count" is used outside of the cfloop. Inside the cfloop the only thing I wanted was to say count = count + 1. However this does not appear to change the value of "count" OUTSIDE of the cfloop.

Is there a way I can make it change the value of "count" outside of the cfloop?
 
Unless you're using the VAR scope, using a scoped variable should work, or you can use a conditional loop

Code:
<cfset variables.count = 0>
<cfloop from="1" to="15" index="variables.count">
	<cfset count = count + 1>
	<cfoutput>the count is now #count#<br></cfoutput>
</cfloop>
<cfoutput>finshed: #count#</cfoutput>

<cfset count = 0>
<cfloop condition="count LTE 15">
	<cfset count = count + 1>
</cfloop>
<cfoutput>#count#</cfoutput>
 
You hit the nail on the head. Thanks!! That is exactly what I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top