summaryrefslogtreecommitdiff
path: root/pod/perlsyn.pod
diff options
context:
space:
mode:
authorPeter Martini <PeterCMartini@GMail.com>2014-06-02 07:16:59 -0400
committerJames E Keenan <jkeenan@cpan.org>2014-06-24 07:15:08 -0400
commit62bd8e4fad23113559e433ef006421d173514730 (patch)
tree05c4e5c47d0026d53b246ff176ad4baaddee4180 /pod/perlsyn.pod
parentb65827489f432c6b8ea39e1ae6abef4e8d8b0723 (diff)
downloadperl-62bd8e4fad23113559e433ef006421d173514730.tar.gz
Document empty conditional in for/while
An empty conditional in both for and while has been treated as true since perl 1.0. This has a clear analogue in C/C++ in the case of for(;;), but while() is not legal C and should be documented.
Diffstat (limited to 'pod/perlsyn.pod')
-rw-r--r--pod/perlsyn.pod15
1 files changed, 15 insertions, 0 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index 244372c8c2..cea4d5001f 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -429,6 +429,21 @@ those variables is exactly the C<for> loop (the body of the loop
and the control sections).
X<my>
+As a special case, if the test in the C<for> loop (or the corresponding
+C<while> loop) is empty, it is treated as true. That is, both
+
+ for (;;) {
+ ...
+ }
+
+and
+
+ while () {
+ ...
+ }
+
+are treated as infinite loops.
+
Besides the normal array index looping, C<for> can lend itself
to many other interesting applications. Here's one that avoids the
problem you get into if you explicitly test for end-of-file on