language/control-structures/continue.xml
16389a7b31069481d6c8c0705172bee5ef1ddf5f
...
...
@@ -2,7 +2,7 @@
2
2
<!-- $Revision$ -->
3
3

4
4
<sect1 xml:id="control-structures.continue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
-
<title><literal>continue</literal></title>
5
+
<title>continue</title>
6
6
<?phpdoc print-version-for="continue"?>
7
7
<simpara>
8
8
<literal>continue</literal> is used within looping structures to
...
...
@@ -11,10 +11,15 @@
11
11
</simpara>
12
12
<note>
13
13
<simpara>
14
-
Note that in PHP the
14
+
In PHP the
15
15
<link linkend="control-structures.switch">switch</link> statement is
16
16
considered a looping structure for the purposes of
17
-
<literal>continue</literal>.
17
+
<literal>continue</literal>. <literal>continue</literal> behaves like
18
+
<literal>break</literal> (when no arguments are passed) but will
19
+
raise a warning as this is likely to be a mistake. If a
20
+
<literal>switch</literal> is inside a loop,
21
+
<literal>continue 2</literal> will continue with the next iteration
22
+
of the outer loop.
18
23
</simpara>
19
24
</note>
20
25
<simpara>
...
...
@@ -28,29 +33,63 @@
28
33
<programlisting role="php">
29
34
<![CDATA[
30
35
<?php
31
-
while (list($key, $value) = each($arr)) {
32
-
if (!($key % 2)) { // skip odd members
36
+
$arr = ['zero', 'one', 'two', 'three', 'four', 'five', 'six'];
37
+
foreach ($arr as $key => $value) {
38
+
if (0 === ($key % 2)) { // skip members with even key
33
39
continue;
34
40
}
35
-
do_something_odd($value);
41
+
echo $value . "\n";
36
42
}
37
-

43
+
?>
44
+
]]>
45
+
</programlisting>
46
+
&examples.outputs;
47
+
<screen>
48
+
<![CDATA[
49
+
one
50
+
three
51
+
five
52
+
]]>
53
+
</screen>
54
+
<programlisting role="php">
55
+
<![CDATA[
56
+
<?php
38
57
$i = 0;
39
58
while ($i++ < 5) {
40
-
echo "Outer<br />\n";
59
+
echo "Outer\n";
41
60
while (1) {
42
-
echo "Middle<br />\n";
61
+
echo "Middle\n";
43
62
while (1) {
44
-
echo "Inner<br />\n";
63
+
echo "Inner\n";
45
64
continue 3;
46
65
}
47
-
echo "This never gets output.<br />\n";
66
+
echo "This never gets output.\n";
48
67
}
49
-
echo "Neither does this.<br />\n";
68
+
echo "Neither does this.\n";
50
69
}
51
70
?>
52
71
]]>
53
72
</programlisting>
73
+
&examples.outputs;
74
+
<screen>
75
+
<![CDATA[
76
+
Outer
77
+
Middle
78
+
Inner
79
+
Outer
80
+
Middle
81
+
Inner
82
+
Outer
83
+
Middle
84
+
Inner
85
+
Outer
86
+
Middle
87
+
Inner
88
+
Outer
89
+
Middle
90
+
Inner
91
+
]]>
92
+
</screen>
54
93
</informalexample>
55
94
</para>
56
95
<para>
...
...
@@ -81,21 +120,6 @@ for ($i = 0; $i < 5; ++$i) {
81
120
4
82
121
]]>
83
122
</screen>
84
-
<para>
85
-
but this script will output:
86
-
</para>
87
-
<screen>
88
-
<![CDATA[
89
-
2
90
-
]]>
91
-
</screen>
92
-
<para>
93
-
because the entire <literal>continue print "$i\n";</literal> is evaluated
94
-
as a single expression, and so <function>print</function> is called only
95
-
when <literal>$i == 2</literal> is true. (The return value of
96
-
<literal>print</literal> is passed to <literal>continue</literal> as the
97
-
numeric argument.)
98
-
</para>
99
123
</informalexample>
100
124
</para>
101
125
<para>
...
...
@@ -110,17 +134,10 @@ for ($i = 0; $i < 5; ++$i) {
110
134
</thead>
111
135
<tbody>
112
136
<row>
113
-
<entry>5.4.0</entry>
114
-
<entry>
115
-
<literal>continue 0;</literal> is no longer valid. In previous versions it was interpreted
116
-
the same as <literal>continue 1;</literal>.
117
-
</entry>
118
-
</row>
119
-
<row>
120
-
<entry>5.4.0</entry>
137
+
<entry>7.3.0</entry>
121
138
<entry>
122
-
Removed the ability to pass in variables (e.g., <literal>$num = 2; continue $num;</literal>)
123
-
as the numerical argument.
139
+
<literal>continue</literal> within a <literal>switch</literal> that is attempting to act like a <literal>break</literal> statement for the
140
+
<literal>switch</literal> will trigger an <constant>E_WARNING</constant>.
124
141
</entry>
125
142
</row>
126
143
</tbody>
127
144