4 Replies Latest reply on Jan 7, 2009 11:25 AM by Newsgroup_User

    Conditional loop

    pkonshak Level 1
      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!
        • 1. Re: Conditional loop
          BKBK Adobe Community Professional & MVP
          <Cfloop condition="findvar GT 0">
          <cfset findvar = findnocase(form.searchterm, searchfile, findvar+1)>
          Position in file: <cfoutput>#findvar#</cfoutput><br>
          </cfloop>
          • 2. Re: Conditional loop
            pkonshak Level 1
            This worked great...thanks so much.

            Though I'm not sure why mine didn't work (something with the variables..?)
            • 3. Re: Conditional loop
              Level 7
              pkonshak wrote:
              > This worked great...thanks so much.
              >
              > Though I'm not sure why mine didn't work (something with the variables..?)

              You didn't have the findvar + 1. So subsequent searches, after the fist
              loop iteration, started right at the first found string. Thus finding
              it again and again and again and again and again... I think you get the
              idea.
              • 4. Re: Conditional loop
                Dan Bracuk Level 5
                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.