Home > Community > Forums > Custom IC SKILL > How to stop the current iteration and start the next iteration of the loop( for/while ) in skill?

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 stop the current iteration and start the next iteration of the loop( for/while ) in skill? 

Last post Thu, Mar 4 2010 5:06 AM by cwgong. 4 replies.
Started by cwgong 03 Mar 2010 01:17 PM. Topic has 4 replies and 4163 views
Page 1 of 1 (5 items)
Sort Posts:
  • Wed, Mar 3 2010 1:17 PM

    • cwgong
    • Not Ranked
    • Joined on Wed, Mar 3 2010
    • Posts 3
    • Points 30
    How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? Reply

     Hi All,

        The title is my question. " How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? ".

        I tried to loop some input data, but some data will invoke error during the iteration, and the programming would be stopped and exit. So I need a key word like "continue" in language C or "next" in perl to ignore the unusual process and go to the next iteration in the loop. I tried to explore some documents, but got nothing.

        So, could anyone can give me some reference about this issue?

        Thanks very much.

     

     

     

    • Post Points: 20
  • Wed, Mar 3 2010 1:36 PM

    • kbhow
    • Top 75 Contributor
    • Joined on Thu, May 7 2009
    • Penang, Pulau Pinang
    • Posts 120
    • Points 2,045
    Re: How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? Reply

    HI cwgong,

    There are few recommended function that you can use to allow executions to proceed untill the next expression.There are next(), break() and go(). In SKILL coding, there is next() function as well.

     

    How

    • Post Points: 35
  • Wed, Mar 3 2010 2:15 PM

    Re: How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? Reply

    The next() and break() functions are for the SKILL debugger. They are NOT equivalent to functions in other languages which continue to the next point in a loop, or break out of a loop. The go() function is a goto in SKILL. I've never used it, and have avoided it like the plague - I'm opposed to it on philosophical grounds (I think it has no place in a functional language).

    There are several ways you can do loops which exit early. For example:

    lst='(1 2 3 4 0 5 6 7)
    forall(item lst
        when(errset(div=100.0/item)
            printf("100.0/%d is %g\n" item div)
            t
        )
    )

    Similarly you could use the exists() function to iterate over a list until a match is made. Or you could use a while loop, taking the cdr each time:

    status=t
    ptr=lst
    while(status && ptr
       item=car(ptr)
       if(some_bad_condition then
         status=nil
       else
         ptr=cdr(ptr)
       )
    )

    Or if you want to use a jump-out type approach, you could use:

    prog(()
      foreach(item lst
        if(errset(div=100.0/item) then
          printf("100.0/%d is %g\n" item div)
        else
          return()
        )
      )
    )

    The return is returning from the prog() - and although it happens in the middle of the foreach, it will jump out of the foreach cleanly. 

    Personally I don't tend to like this approach, because it's a bit of a goto in disguise, and it's still smacks of "spaghetti programming" to me. But I can see that for some difficult to handle errors, it could be useful.

    Regards,

    Andrew.

    • Post Points: 20
  • Thu, Mar 4 2010 5:05 AM

    • cwgong
    • Not Ranked
    • Joined on Wed, Mar 3 2010
    • Posts 3
    • Points 30
    Re: How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? Reply

     Hi, Thanks very much for your recommended function, but it seems that the function "next()" is just for debugger. :(

    • Post Points: 5
  • Thu, Mar 4 2010 5:06 AM

    • cwgong
    • Not Ranked
    • Joined on Wed, Mar 3 2010
    • Posts 3
    • Points 30
    Re: How to stop the current iteration and start the next iteration of the loop( for/while ) in skill? Reply

     Hi,

      Thanks very much for your replyment. I think I got the point.

     

    • Post Points: 5
Page 1 of 1 (5 items)
Sort Posts:
Started by cwgong at 03 Mar 2010 01:17 PM. Topic has 4 replies.