summaryrefslogtreecommitdiff
path: root/pod/perlsyn.pod
diff options
context:
space:
mode:
authorabela@geneanet.org <abela@geneanet.org>2001-03-06 10:40:36 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2001-03-07 15:04:58 +0000
commitb78df5de4cbb361d400476487114def2ea80ea60 (patch)
tree7a25e0e4ad2cb3dcb2f3eed170ea83ff8d492f70 /pod/perlsyn.pod
parent910e2c00e1560aec9f2660860b8fb831a5c9fc0f (diff)
downloadperl-b78df5de4cbb361d400476487114def2ea80ea60.tar.gz
Clarify the description differentiating for and while; inspired by
Subject: [ID 20010306.002] for/while difference in for definition Message-Id: <20010306084036.7BFD0D17F@little-roots.geneanet.org> p4raw-id: //depot/perl@9070
Diffstat (limited to 'pod/perlsyn.pod')
-rw-r--r--pod/perlsyn.pod8
1 files changed, 5 insertions, 3 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index e6b420e5db..aad4efd2f7 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -263,7 +263,7 @@ available. Replace any occurrence of C<if BLOCK> by C<if (do BLOCK)>.
=head2 For Loops
-Perl's C-style C<for> loop works exactly like the corresponding C<while> loop;
+Perl's C-style C<for> loop works like the corresponding C<while> loop;
that means that this:
for ($i = 1; $i < 10; $i++) {
@@ -279,8 +279,10 @@ is the same as this:
$i++;
}
-(There is one minor difference: The first form implies a lexical scope
-for variables declared with C<my> in the initialization expression.)
+There is one minor difference: if variables are declared with C<my>
+in the initialization section of the C<for>, the lexical scope of
+those variables is exactly the C<for> loop (the body of the loop
+and the control sections).
Besides the normal array index looping, C<for> can lend itself
to many other interesting applications. Here's one that avoids the