Stopping a Repeat Until Loop

sabzamsabzam Member Posts: 1,149
Dear All,

I have got a repeat until loop and I need to stop a particular cycle and go to the next loop in certain conditions. The only method which I've found out so far is to use the begin...end within the repeat until but I'm looking for a cleaner way. Does anyone know of an alternative?

Regards,

Steve

Comments

  • kapamaroukapamarou Member Posts: 1,152
    It depends on what you need to achieve.
    You can do something like

    REPEAT

    UNTIL ((NEXT = 0) OR (MyBoolean = FALSE))

    But keep in mind that the last NEXT will be called before exiting and the pointer will move to the next record.

    What exactly do you want to do?
  • vijay_gvijay_g Member Posts: 884
    edited 2011-02-09
    Try this....
    Rec.findset then 
       repeat
           if condition = true then
             Loopexit := true;
       until (Rec.Next=0) or (Loopexit = true);
    
  • sabzamsabzam Member Posts: 1,149
    The issue is that I do not want to go through the whole cycle. I can set as loopexit = true or something of the sort but I was looking for a function similar to break which would go to the next loop.
  • bbrownbbrown Member Posts: 3,268
    Put that section of code in its own function. Then you can place the EXIT where you want.
    There are no bugs - only undocumented features.
  • sabzamsabzam Member Posts: 1,149
    Ok thanks to everyone
  • David_SingletonDavid_Singleton Member Posts: 5,479
    vijay_g wrote:
           if condition = true then
    

    ](*,) ](*,) ](*,) ](*,) ](*,) ](*,) ](*,) ](*,)
    David Singleton
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    vijay_g wrote:
           if condition = true then
    

    ](*,) ](*,) ](*,) ](*,) ](*,) ](*,) ](*,) ](*,)


    Are you expection
    if condition then
    ???
  • David_SingletonDavid_Singleton Member Posts: 5,479


    Are you expection
    if condition then
    ???

    Yes. :D
    David Singleton
  • Alex_ChowAlex_Chow Member Posts: 5,063
  • bbrownbbrown Member Posts: 3,268
    sabzam wrote:
    Dear All,

    I have got a repeat until loop and I need to stop a particular cycle and go to the next loop in certain conditions. The only method which I've found out so far is to use the begin...end within the repeat until but I'm looking for a cleaner way. Does anyone know of an alternative?

    Regards,

    Steve


    If I understand you correctly, you are looking to break out of a particular cycle thru the Repeat..Until loop but continue the loop with the next value. Not break entirely out of the loop.
    Rec.findset then 
       repeat
         LoopFunction;
       until (Rec.Next=0);
    
      Function LoopFunction
    
        // [place code here to process each loop cycle.  You can then exit this fucntion where desired and the Repeat..Until will continue with the next record.
    
    There are no bugs - only undocumented features.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Never mind... I see now. :oops:
    David Singleton
  • bbrownbbrown Member Posts: 3,268
    Yes, and they all terminate the loop. But I don't think that is what he is trying to do. I think he is trying to abort a single run thru the loop (based on some condition) but continue with the next record.

    But then I could be wrong... :-$
    There are no bugs - only undocumented features.
  • MGM08MGM08 Member Posts: 41
    Hi,

    do u want a code like breaking the whole loop or like skip the particular record in that loop?
  • Yashojit_PandhareYashojit_Pandhare Member Posts: 38
    You can use Exit, when a particular condition is met, for example

    REPEAT
    <SOME CODE HERE>
    IF Condition THEN
    EXIT;
    <SOME CODE HERE>
    UNTIL rec.NEXT=0;
Sign In or Register to comment.