http://www.perlmonks.org?node_id=496810


in reply to If I was forced to use only one kind of loop for the rest of my days it would be a

Definitely a foreach over a for

Wouldn't want to be stuck with a $_ in my loops now for the rest of my life. I prefer a meaningful name for the it variable

  • Comment on Re: If I was forced to use only one kind of loop for the rest of my days it would be a

Replies are listed 'Best First'.
Re^2: If I was forced to use only one kind of loop for the rest of my days it would be a
by Moron (Curate) on Oct 04, 2005 at 11:25 UTC
    (Updated) I rather feel some people would regret their choices. Only recursion can replace all the others, although I voted for for, because recursion is not technically a loop and in many replacement scenarios it would need some horrible overworking to overcome certain scoping issues, but for has enough machinery to replace everything else except recursion. For example, while (condition) is functionally the same as for (;condition;) and do {} while (condition) could be replaced by for (my $first = 1; $first or condition; $first=0) {}