Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I cause a loop to jump to the next loop item?

Enthusiast ,
May 29, 2009 May 29, 2009

How do I cause a loop to jump to the next loop item? cfbreak exits all the loop which I don't want

<cfloop condition="i LESS THAN OR EQUAL TO #ArrayLen(arrData)#">
       
        <!--- we need to filter out problem rows so the uplaod doesn't crash'--->
        <cfif not REFind("^[0-2][0-9][/][0-1][0-2][/][1-2][0-9]{3}$", arrData[1] ) > <!--- Deal date--->
            jump to next loop item  (ie i++)
        </cfif>

thanks

2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 22, 2009 Jun 22, 2009
<cfset i=i+1>  does not cause the loop to jump to the next loop item, it mearly incraments the var i.


<cfset i=i+1> does in fact cause the loop to jump to the next item. This is inevitable, because i is your loop's index.

In any case, as others have suggested, you can ignore the i story altogether. Just follow your own instinct and code it directly as you feel it.

I want to check each row but if there is any error in any column in that row I want to ignore the entire row

<cfloop>

<cfset isRowErrorFre

...
Translate
Community Expert ,
May 29, 2009 May 29, 2009

<cfloop condition="i LESS THAN OR EQUAL TO #ArrayLen(arrData)#">            
        <cfif >  

            <cfset i=i+1> 
        </cfif>

</cfloop>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2009 May 29, 2009

There does not appear to be any need for a cfbreak at all.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 29, 2009 May 29, 2009

why is that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2009 May 29, 2009

Because the code comments in the OP suggest that you want to process the entire array.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 22, 2009 Jun 22, 2009

I want to check each row but if there is any error in any column in that row I want to ignore the entire row,

the code

<cfset i=i+1>  does not cause the loop to jump to the next loop item, it mearly incraments the var i.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2009 Jun 22, 2009

Read Ian's answer again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2009 Jun 22, 2009
<cfset i=i+1>  does not cause the loop to jump to the next loop item, it mearly incraments the var i.


<cfset i=i+1> does in fact cause the loop to jump to the next item. This is inevitable, because i is your loop's index.

In any case, as others have suggested, you can ignore the i story altogether. Just follow your own instinct and code it directly as you feel it.

I want to check each row but if there is any error in any column in that row I want to ignore the entire row

<cfloop>

<cfset isRowErrorFree = true>

<!--- code to check for error in row; if error found, set isRowErrorFree = false --->

<cfif isRowErrorFree>

     <!--- code to do the required calculation --->

</cfif>

</cfloop>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 24, 2009 Jun 24, 2009
LATEST

Cool, thanks guys

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 29, 2009 May 29, 2009

Just use your if else logic to determine what goes on in each iteration of the loop.

<cfloop ...>

  <cfif this>

    DO THIS

   <cfelse>

    DO THAT

  </cfif>

</cfloop>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources