in reply to Re (3): Thoughts on naming loop LABEL: (TMTOWTDI, why label loops?)
in thread Thoughts on naming loop LABEL:

Do you label all such blocks or loops to make it clear that you are short circuiting the loop when you have a next, last, or redo?

LINE: while(<>) { # ... next LINE if ... # ... } SEARCH: for (@list) { # ... last SEARCH if ... }

Do you do so only in long blocks? Complicated blocks? Do you have a consistent style for when and how to label loops or is it more of a "whatever seems good at the time" approach? I ask not to be difficult but because in a single non-nested loop I just don't see any additional clarity being added by loop labels. If you see a benefit can you describe the situations where you find it beneficial versus those where it is ok to not label the loop?

  • Comment on Re: Re (3): Thoughts on naming loop LABEL: (TMTOWTDI, why label loops?)
  • Download Code

Replies are listed 'Best First'.
Re (5): Thoughts on naming loop LABEL: (TMTOWTDI, why label loops?)
by VSarkiss (Monsignor) on May 02, 2002 at 17:26 UTC

    Hmm, good question. I don't think I have any specific rules, but I seem to do it based on some notion of "distance": if the next or last is "a long way" from the top or bottom of the loop, I'll put in a label. Ultimately, it's a question of "if it looks better with the label, add it", but I can't quantify what I mean by "better".

    On the other hand, I don't think I've ever used a label with redo (I don't use it very often 'cause I find it confusing. ;-)