Skip to main content
nikos101
Inspiring
May 29, 2009
Answered

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

  • May 29, 2009
  • 3 replies
  • 2649 views

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

    This topic has been closed for replies.
    Correct answer BKBK

    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.


    <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>

    3 replies

    ilssac
    Inspiring
    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>

    Inspiring
    May 29, 2009

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

    nikos101
    nikos101Author
    Inspiring
    May 29, 2009

    why is that?

    nikos101
    nikos101Author
    Inspiring
    June 22, 2009

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


    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.

    BKBK
    Community Expert
    May 29, 2009

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

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

    </cfloop>