On 2011-10-12 19:40, Simen Kjaeraas wrote:
On Wed, 12 Oct 2011 19:00:56 +0200, Jacob Carlborg <[email protected]> wrote:
On 2011-10-12 18:18, Gor Gyolchanyan wrote:
You never know when exactly and in which conditions will that delegate
get called. You can't decide to quit something you don't know anything
about.
If a function implements something similar to a loop I would like to
be able to abort it with a return just as you can with a loop built
into the language.
void loop (void delegate () dg)
{
while (true)
dg();
}
loop
{
if (someCondition)
return; // stops the loop
}
However, a lot of code using this syntax would be more complex than what
you indicate. Should it work simply as a break in the loop? What if it
is a recursive function? There is a reason why opApply is designed the
way it is.
This answer to a stack overflow question explains how it works in Ruby:
http://stackoverflow.com/questions/1402757/how-to-break-out-from-a-ruby-block#answer-1402764
--
/Jacob Carlborg