[EMAIL PROTECTED] writes:
> On Tue, Apr 09, 2002 at 01:49:01PM +0300, Ilmari Karonen wrote:
> > On Fri, 5 Apr 2002 [EMAIL PROTECTED] wrote:
> > > sub shuffle {
> > > for (my $i = @_; $i;) {
> > > my $j = rand $i --;
> > > @_ [$i => $j] = @_ [$j => $i]
> > > }
> > > @_;
> > > }
> >
> > I could live with that. To really go into the FAQ, though, it'd need an
> > explanatory paragraph or two, about how it works and why. And I'd also
> > insist on using a while loop instead of for, even if it costs a line.
>
> I think a while loop isn't right. You have an iterator with an obvious
> starting value, which gets decremented with the same amount in each
> iteration. If that isn't screaming 'for', you might as well start
> deprecating 'for'.
Haven't you heard? In perl 6, "for" will replace "foreach" and the
C-style "for" will be called "loop." Larry says that the C-style
"for" loop is used far less often than the "foreach" style. Sounds
like it's being deprecated...
The canonical C-style "for" is for(my $i = 0; $i < something; $i++).
Your loop has the decrement inside the loop, which is the main
motivator for the "for" syntax. I agree that a "while" would be more
logical to the novice.
--Bill.
--
William R Ward [EMAIL PROTECTED] http://www.wards.net/~bill/
-----------------------------------------------------------------------------
If you're not part of the solution, you're part of the precipitate.