[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I'd give my right arm for a continue statement
- From: Dirk Laurie <dpl@...>
- Date: Mon, 24 Jan 2011 22:11:48 +0200
On Sun, Jan 23, 2011 at 09:18:45PM +0200, Shmuel Zeigerman wrote:
>
> And what if `continue' is needed from within deeply nested blocks? Even
> with depth of 2 (as in an example below) there's no simple replacement
> to it.
>
> while condition do
> -- some code
> if test1 then
> -- more code
> if test2 then
> continue
> end
> -- more code
> end
> -- more code
> end
>
Well, the obfuscated solution involving repeat until false could be
defended on the grounds that it is an idiom, I suppose. But actually
the moment it gets that complicated, I prefer:
function task_description_saving_a_comment()
if test1 then
-- more code
if test2 then
return
end
-- more code
end
end
while condition do
task_description_saving_a_comment()
end
If you need break and continue in the same loop, the function
could return true or false.
Dirk
- References:
- Re: I'd give my right arm for a continue statement, Michal Kottman
- Re: I'd give my right arm for a continue statement, steve donovan
- Re: I'd give my right arm for a continue statement, Axel Kittenberger
- Re: I'd give my right arm for a continue statement, David Kastrup
- Re: I'd give my right arm for a continue statement, GrayFace
- Re: I'd give my right arm for a continue statement, T T
- Re: I'd give my right arm for a continue statement, David Kastrup
- Re: I'd give my right arm for a continue statement, Mark Hamburg
- Re: I'd give my right arm for a continue statement, Dirk Laurie
- Re: I'd give my right arm for a continue statement, Shmuel Zeigerman