On 2/7/07, Rob Dixon <[EMAIL PROTECTED]> wrote:
Igor Sutton wrote:
> Hi fellows,
>
>> Dave, you wanted to use
>>
>> while (1) {
>>   ...
>>   the code to be repeated
>>   ..
>> }
>>
>
> The above code could be written like this:
>
> {
>    ...
>    # the code to be repeated
>    ...
>    redo;
> }
>
> Do you think this is better or worse than the other idiom? I like the
> last more.

You are welcome to use it, but beware that people reading your code may not
understand what you are doing. 'redo' is uncommon and not universally known.
Furthermore it is easy to miss as it camouflaged at the same indent level as and
at the end of the block of code to be repeated. The first example proclaims
loudly that the following block is to be repeated indefinitely, while the second
mutters the same thing about the block it is part of.

I think Rob got the point here. This subtle construction may be made
more explicit by using explicit labels like this:

LOOP: {
   ...
   # the code to be repeated
   ...
   redo LOOP;
}

It helps readability, but not that much for people not used to Perl.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to