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.
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.
In reply to kbhow:
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=tptr=lstwhile(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.
Hi, Thanks very much for your recommended function, but it seems that the function "next()" is just for debugger. :(
In reply to Andrew Beckett:
Thanks very much for your replyment. I think I got the point.