- next
- last
Loop controls: next, last
- next - evaluate the loop condition and if it is true go to the next iteration. (continue in other languages)
- last - exit the loop. (break in other languages)
- redo - start the iteration again without evaluating the loop condition.
examples/perlarrays/loop_control.txt
First line Line after empty line Another text line __END__ Some text here that won't be printed
examples/files-perl/loop_control.pl
#!/usr/bin/perl use strict; use warnings; my $counter = 0; my $total = 0; while (1) { $counter++; my $num = rand(1); # print "Debug: $num $total\n"; if ($num < 0.2) { next; } $total += $num; if ($total > 3) { last; } ### next jumps here ### } ### last jumps here ### print "Counter: $counter Total: $total\n"
'First line' 'Line after empty line' 'Another text line' Number of non empty rows: 3 out of a total of 6