This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't pollute $ENV{LC_ALL} in pod/perlmodlib.PL.
[perl5.git] / pod / perlsyn.pod
index 01425d2..a5e075d 100644 (file)
@@ -181,23 +181,35 @@ This is so that you can write loops like:
 See L<perlfunc/do>.  Note also that the loop control statements described
 later will I<NOT> work in this construct, because modifiers don't take
 loop labels.  Sorry.  You can always put another block inside of it
-(for C<next>) or around it (for C<last>) to do that sort of thing.
-For C<next>, just double the braces:
+(for C<next>/C<redo>) or around it (for C<last>) to do that sort of thing.
 X<next> X<last> X<redo>
 
+For C<next> or C<redo>, just double the braces:
+
     do {{
         next if $x == $y;
         # do something here
     }} until $x++ > $z;
 
-For C<last>, you have to be more elaborate:
+For C<last>, you have to be more elaborate and put braces around it:
 X<last>
 
+    {
+        do {
+            last if $x == $y**2;
+            # do something here
+        } while $x++ <= $z;
+    }
+
+If you need both C<next> and C<last>, you have to do both and also use a
+loop label:
+
     LOOP: {
-            do {
-                last if $x = $y**2;
-                # do something here
-            } while $x++ <= $z;
+        do {{
+            next if $x == $y;
+            last LOOP if $x == $y**2;
+            # do something here
+        }} until $x++ > $z;
     }
 
 B<NOTE:> The behaviour of a C<my>, C<state>, or
@@ -219,8 +231,8 @@ a C<next> from inside a C<foreach> and C<break> from inside a C<given>.
 
 Under the current implementation, the C<foreach> loop can be
 anywhere within the C<when> modifier's dynamic scope, but must be
-within the C<given> block's lexical scope.  This restricted may
-be relaxed in a future release.  See L<"Switch Statements"> below.
+within the C<given> block's lexical scope.  This restriction may
+be relaxed in a future release.  See L</"Switch Statements"> below.
 
 =head2 Compound Statements
 X<statement, compound> X<block> X<bracket, curly> X<curly bracket> X<brace>
@@ -399,7 +411,7 @@ they aren't loops.  You can double the braces to make them such, though.
     }}
 
 This is caused by the fact that a block by itself acts as a loop that
-executes once, see L<"Basic BLOCKs">.
+executes once, see L</"Basic BLOCKs">.
 
 The form C<while/if BLOCK BLOCK>, available in Perl 4, is no longer
 available.   Replace any occurrence of C<if BLOCK> by C<if (do BLOCK)>.