Welcome to openkapow Sign in | Join
in Search
.

exit loop

Last post 06-01-2007, 4:36 PM by bighero. 9 replies.
Sort Posts: Previous Next
  •  05-28-2007, 6:03 PM 10626

    exit loop

    Is it possible to exit a loop when certain conditions are met? Say i want to exit the loop when my global variable is greater than 10. Is this possible?
    Filed under:
  •  05-28-2007, 7:40 PM 10627 in reply to 10626

    Re: exit loop

    I wish I knew the answer! For your information, you can look at this other open thread: "[How to?] exit a loop when a condition is met?"
    http://openkapow.com/forums/thread/8359.aspx

  •  05-29-2007, 1:06 AM 10638 in reply to 10626

    Re: exit loop

    Here's a sample how you can "quit' a for-each loop:

    http://openkapow.com/files/folders/tutorials_and_examples/entry10637.aspx 

     

  •  05-29-2007, 4:33 AM 10644 in reply to 10638

    Re: exit loop

    You are not exiting the loop. You seem to run the whole loop and if a test fails, you increase the counter and re-test again.

    The question is how to *really* exit a loop: if a condition is false, then go out of the loop, do not increment the counter, do not retest. something like "repeat... until". To my knowledge, this is not possible in Robomaker. I hope it will come in a future release.

  •  05-29-2007, 9:41 AM 10653 in reply to 10644

    Re: exit loop

    ppow:
    You are not exiting the loop. You seem to run the whole loop and if a test fails, you increase the counter and re-test again.

    The question is how to *really* exit a loop: if a condition is false, then go out of the loop, do not increment the counter, do not retest. something like "repeat... until". To my knowledge, this is not possible in Robomaker. I hope it will come in a future release.

     

    You are right! That was the reason why I wrote "quite" between  quotes. But I gave Bighero a working solution for his problem...

     

    Btw. Why do you need a repeat/until functionality ? (I can always learn)

  •  05-29-2007, 6:54 PM 10673 in reply to 10653

    Re: exit loop

    "Repeat / until" is the equivalent of exiting a loop when a condition is met:

    Repeat
      Action
    Until ConditionA is true

    is similar to

    Loop: For i=1 ->10
      Action
      If conditionA then exit loop
    Next (go back to the begining of the loop)

  •  05-30-2007, 12:46 AM 10676 in reply to 10673

    Re: exit loop

    Thanks for your explanation but I know how a repeat/until works. But do you have an example of a application/robot where you need this kind of a loop ?  Or is just a "shorter way" of programming of a robot the reason that you want this feature?

     

  •  05-30-2007, 1:38 AM 10678 in reply to 10676

    Re: exit loop

    Sorry, I misread you there.

    I prefer repeat/until to a plain loop just for performance reasons. I do not want to run and fail the same test over and over again in a loop.

    A typical application is when I want to create a RSS feed with the top 2 stories based on a condition (containing a keyword or something). My For each tag loop would return hundreds of entries, but when I find 2 entries matching a condition, then I want to escape. This is because new data comes now and then, so it is most efficient to create a RSS feed with 2 entries only.

  •  05-31-2007, 5:14 AM 10706 in reply to 10678

    Re: exit loop

    I agree with you that  that a repeat/until loop could be very usefull but because of different reason.

     Typically for RSS feeds is that performance is not an issue. The loop is completely cached in the roboserver so even with hundreds of items I don't think performance is an issue BUT... if you have to "click" each item to get the full text then performance IS an issue. And moreover, the siteowner won't be that happy with so many useless clicks in the sitestatistics. So you got my vote.

  •  06-01-2007, 4:36 PM 10769 in reply to 10638

    Re: exit loop

    AHA. "Test Attributes" was just what i needed. I looked for something called "if then" but failed. Guess I was looking in the wrong place.

    Thanks  a bunch

View as RSS news feed in XML
.
Copyright 2006, 2007 KapowTech.com All Rights Reserved Company | Contact | Terms | Privacy