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
...
...
@@ -33,29 +33,63 @@
33
33
<programlisting role="php">
34
34
<![CDATA[
35
35
<?php
36
+
$arr = ['zero', 'one', 'two', 'three', 'four', 'five', 'six'];
36
37
foreach ($arr as $key => $value) {
37
-
if (!($key % 2)) { // skip even members
38
+
if (0 === ($key % 2)) { // skip members with even key
38
39
continue;
39
40
}
40
-
do_something_odd($value);
41
+
echo $value . "\n";
41
42
}
42
-

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