Home > Community > Forums > Custom IC SKILL > How to come out of loop after x iterations.

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 How to come out of loop after x iterations. 

Last post Mon, Mar 9 2009 11:15 PM by SUBBHAREDDY. 3 replies.
Started by SUBBHAREDDY 06 Mar 2009 09:19 PM. Topic has 3 replies and 2801 views
Page 1 of 1 (4 items)
Sort Posts:
  • Fri, Mar 6 2009 9:19 PM

    How to come out of loop after x iterations. Reply

    Hi Guys

     I am writing a skill code for for loop.Which executes statements  for 10 iterations.

    I am keeping a check point at 8th iteration loop,and i want to come out of the loop,if my condition is satisfied.

    I don't want to come out of my program,only come out of for loop only.

     Pls let me know ?

     Thanks and regards

    Subbhareddy 

    • Post Points: 5
  • Sun, Mar 8 2009 9:21 PM

    Re: How to come out of loop after x iterations. Reply

    Any help ?

    • Post Points: 20
  • Mon, Mar 9 2009 2:06 AM

    Re: How to come out of loop after x iterations. Reply

     First thing you could do is to just use a while loop instead:

    count=1 finished=nil while(count<=10 && !finished println(count) when(count==7 finished=t) count++ )
    Or you could use the prog() construct to allow you to return early:
    prog(() for(count 1 10 println(count) when(count==7 return()) ) ; for ) ; prog

    Personally I don't tend to like using the prog() approach - it leads to "spaghetti programming" where you've effectively got hidden jumps out of the code in the middle, which makes the flow of the program harder to understand.

    Regards,

    Andrew.

    • Post Points: 20
  • Mon, Mar 9 2009 11:15 PM

    Re: How to come out of loop after x iterations. Reply

    Hi Andrew

     

    Thanks a lot,It works fine.

    Both are quite good.But in my way we can prefer prog method,i thinks so.

     

    Thanks and regards

    Subbhareddy

    • Post Points: 5
Page 1 of 1 (4 items)
Sort Posts:
Started by SUBBHAREDDY at 06 Mar 2009 09:19 PM. Topic has 3 replies.