On Tue, May 15, 2018 at 03:31:07PM -0700, ToddAndMargo wrote:
: Hi All,
: 
: This seems like a trivial question, but I really adore
: the "for" loops.  Is there a way to do the backwards?
: In other words, start at the end of the array and loop
: to the beginning?  Does the "next" and "last" work in
: this?

Just use the reverse method:

    > my @foo = <a b c>;
    [a b c]
    > for @foo.reverse { .say }
    c
    b
    a

or (as in Perl 5) the reverse function:

    > for reverse @foo { .say }
    c
    b
    a

and yes, "next" and "last" work for those loops too, since they are
controlled by the "for", not by the expression you feed to the "for".

Larry

Reply via email to