Skip to main content
Known Participant
January 7, 2009
Answered

Conditional loop

  • January 7, 2009
  • 1 reply
  • 455 views
Hi,

I have what I thought was a simple conditional loop to find each occurence of a serach string within a variable. Basically trying to find the occurence, note it, then move on. If findnocase can't find an occurence, it should return 0, ending the loop:

<cfset findvar = 1>

<Cfloop condition="findvar GT 0">
<cfoutput>
<cfset findvar = #findnocase("#form.searchterm#","#searchfile#",#findvar#)#>
Position in file: #findvar#<br>

</cfoutput>
</cfloop>

This doesn't work at all. Just spins forever and never returns a result.

...help? Thanks!
This topic has been closed for replies.
Correct answer BKBK
<Cfloop condition="findvar GT 0">
<cfset findvar = findnocase(form.searchterm, searchfile, findvar+1)>
Position in file: <cfoutput>#findvar#</cfoutput><br>
</cfloop>

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
January 7, 2009
<Cfloop condition="findvar GT 0">
<cfset findvar = findnocase(form.searchterm, searchfile, findvar+1)>
Position in file: <cfoutput>#findvar#</cfoutput><br>
</cfloop>
pkonshakAuthor
Known Participant
January 7, 2009
This worked great...thanks so much.

Though I'm not sure why mine didn't work (something with the variables..?)
Inspiring
January 7, 2009
quote:

Originally posted by: pkonshak
This worked great...thanks so much.

Though I'm not sure why mine didn't work (something with the variables..?)

Your's didn't work because you didn't change the value of your variable each time through the loop.