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
...
...
@@ -15,7 +15,8 @@
15
15
<link linkend="control-structures.switch">switch</link> statement is
16
16
considered a looping structure for the purposes of
17
17
<literal>continue</literal>. <literal>continue</literal> behaves like
18
-
<literal>break</literal> (when no arguments are passed). If a
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
19
20
<literal>switch</literal> is inside a loop,
20
21
<literal>continue 2</literal> will continue with the next iteration
21
22
of the outer loop.
...
...
@@ -32,29 +33,63 @@
32
33
<programlisting role="php">
33
34
<![CDATA[
34
35
<?php
36
+
$arr = ['zero', 'one', 'two', 'three', 'four', 'five', 'six'];
35
37
foreach ($arr as $key => $value) {
36
-
if (!($key % 2)) { // skip even members
38
+
if (0 === ($key % 2)) { // skip members with even key
37
39
continue;
38
40
}
39
-
do_something_odd($value);
41
+
echo $value . "\n";
40
42
}
41
-

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
42
57
$i = 0;
43
58
while ($i++ < 5) {
44
-
echo "Outer<br />\n";
59
+
echo "Outer\n";
45
60
while (1) {
46
-
echo "Middle<br />\n";
61
+
echo "Middle\n";
47
62
while (1) {
48
-
echo "Inner<br />\n";
63
+
echo "Inner\n";
49
64
continue 3;
50
65
}
51
-
echo "This never gets output.<br />\n";
66
+
echo "This never gets output.\n";
52
67
}
53
-
echo "Neither does this.<br />\n";
68
+
echo "Neither does this.\n";
54
69
}
55
70
?>
56
71
]]>
57
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>
58
93
</informalexample>
59
94
</para>
60
95
<para>
...
...
@@ -85,27 +120,6 @@ for ($i = 0; $i < 5; ++$i) {
85
120
4
86
121
]]>
87
122
</screen>
88
-
<para>
89
-
but, in PHP versions below 5.4.0, this script will output:
90
-
</para>
91
-
<screen>
92
-
<![CDATA[
93
-
2
94
-
]]>
95
-
</screen>
96
-
<para>
97
-
because the entire <literal>continue print "$i\n";</literal> is evaluated
98
-
as a single expression, and so <function>print</function> is called only
99
-
when <literal>$i == 2</literal> is true. (The return value of
100
-
<literal>print</literal> is passed to <literal>continue</literal> as the
101
-
numeric argument.)
102
-
</para>
103
-
<note>
104
-
<para>
105
-
As of PHP 5.4.0, the above example will raise an
106
-
<constant>E_COMPILE_ERROR</constant> error.
107
-
</para>
108
-
</note>
109
123
</informalexample>
110
124
</para>
111
125
<para>
...
...
@@ -120,25 +134,10 @@ for ($i = 0; $i < 5; ++$i) {
120
134
</thead>
121
135
<tbody>
122
136
<row>
123
-
<entry>7.0.0</entry>
124
-
<entry>
125
-
<literal>continue</literal> outside of a loop or <literal>switch</literal>
126
-
control structure is now detected at compile-time instead of run-time as
127
-
before, and triggers an <constant>E_COMPILE_ERROR</constant>.
128
-
</entry>
129
-
</row>
130
-
<row>
131
-
<entry>5.4.0</entry>
132
-
<entry>
133
-
<literal>continue 0;</literal> is no longer valid. In previous versions it was interpreted
134
-
the same as <literal>continue 1;</literal>.
135
-
</entry>
136
-
</row>
137
-
<row>
138
-
<entry>5.4.0</entry>
137
+
<entry>7.3.0</entry>
139
138
<entry>
140
-
Removed the ability to pass in variables (e.g., <literal>$num = 2; continue $num;</literal>)
141
-
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>.
142
141
</entry>
143
142
</row>
144
143
</tbody>
145
144