Loop-Util
view release on metacpan or search on metacpan
loop process_input();
loop(3) process_input();
Parentheses are required around the loop count expression. If no count
is given, the loop is infinite, but `last` can be used to jump out of
the loop. (The `next` and `redo` keywords also work as expected.)
* `iffirst [LABEL] BLOCK [else BLOCK]`
Runs `BLOCK` only on the first loop iteration; if an `else` block is
present it runs for subsequent iterations.
When `LABEL` is present, `iffirst` checks that labeled loop context
instead of the innermost loop. This is useful in nested loops:
OUTER: loop(2) {
loop(3) {
iffirst OUTER { say "hi" }
}
}
`iffirst` works in `loop{}` loops, and also in `for`/`foreach` loops
over arrays and lists. Calling `iffirst` in other loop kinds throws a
runtime error.
* `iflast [LABEL] BLOCK [else BLOCK]`
Runs `BLOCK` only on the last loop iteration; if an `else` block is
present it runs for not-last iterations.
When `LABEL` is present, `iflast` checks that labeled loop context
instead of the innermost loop.
`iflast` works in finite `loop{}` loops, and also in `for`/`foreach`
loops over arrays and lists. Calling `iflast` in other loop kinds
throws a runtime error.
* `ifodd [LABEL] BLOCK [else BLOCK]`
Runs `BLOCK` for odd-numbered iterations (1st, 3rd, 5th...). If an
`else` block is present, it runs on even-numbered iterations.
Note that if you loop through an array, the first iteration (an odd
iteration) has index number 0 (an even number).
When `LABEL` is present, `ifodd` checks that labeled loop context
instead of the innermost loop.
`ifodd` works in `loop{}` loops, and also in `for`/`foreach` loops
over arrays and lists. Calling `ifodd` in other loop kinds throws a
runtime error.
* `ifeven [LABEL] BLOCK [else BLOCK]`
Runs `BLOCK` for even-numbered iterations (2nd, 4th, 6th...). If an
`else` block is present, it runs on odd-numbered iterations.
Note that if you loop through an array, the first iteration (an odd
iteration) has index number 0 (an even number).
When `LABEL` is present, `ifeven` checks that labeled loop context
instead of the innermost loop.
`ifeven` works in `loop{}` loops, and also in `for`/`foreach` loops
over arrays and lists. Calling `ifeven` in other loop kinds throws a
runtime error.
lib/Loop/Util.pm view on Meta::CPAN
loop process_input();
loop(3) process_input();
Parentheses are required around the loop count expression. If no count is
given, the loop is infinite, but C<last> can be used to jump out of the
loop. (The C<next> and C<redo> keywords also work as expected.)
=item * C<iffirst [LABEL] BLOCK [else BLOCK]>
Runs C<BLOCK> only on the first loop iteration; if an C<else> block is present
it runs for subsequent iterations.
When C<LABEL> is present, C<iffirst> checks that labeled loop context instead
of the innermost loop. This is useful in nested loops:
OUTER: loop(2) {
loop(3) {
iffirst OUTER { say "hi" }
}
}
C<iffirst> works in C<loop{}> loops, and also in C<for>/C<foreach> loops over
arrays and lists. Calling C<iffirst> in other loop kinds throws a runtime
error.
=item * C<iflast [LABEL] BLOCK [else BLOCK]>
Runs C<BLOCK> only on the last loop iteration; if an C<else> block is present
it runs for not-last iterations.
When C<LABEL> is present, C<iflast> checks that
labeled loop context instead of the
innermost loop.
C<iflast> works in finite C<loop{}> loops, and also in C<for>/C<foreach>
loops over arrays and lists. Calling C<iflast> in other loop kinds throws a
runtime error.
=item * C<ifodd [LABEL] BLOCK [else BLOCK]>
Runs C<BLOCK> for odd-numbered iterations (1st, 3rd, 5th...).
If an C<else> block is present, it runs on even-numbered iterations.
Note that if you loop through an array, the first iteration (an odd
iteration) has index number 0 (an even number).
When C<LABEL> is present, C<ifodd> checks that
labeled loop context instead of the
innermost loop.
C<ifodd> works in C<loop{}> loops, and also in C<for>/C<foreach> loops over
arrays and lists. Calling C<ifodd> in other loop kinds throws a runtime
error.
=item * C<ifeven [LABEL] BLOCK [else BLOCK]>
Runs C<BLOCK> for even-numbered iterations (2nd, 4th, 6th...).
If an C<else> block is present, it runs on odd-numbered iterations.
Note that if you loop through an array, the first iteration (an odd
iteration) has index number 0 (an even number).
When C<LABEL> is present, C<ifeven> checks that
labeled loop context instead of the
innermost loop.
C<ifeven> works in C<loop{}> loops, and also in C<for>/C<foreach> loops over
arrays and lists. Calling C<ifeven> in other loop kinds throws a runtime
( run in 0.400 second using v1.01-cache-2.11-cpan-71847e10f99 )