Added notes about optional args to break and continue.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@18860 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Torben Wilson 2000-01-27 21:26:37 +00:00
parent a80e9af9ab
commit 2ae0853180

View file

@ -533,43 +533,97 @@ foreach($a as $k => $v) {
</sect1>
<sect1 id="control-structures.break">
<title><literal>break</literal></title>
<sect1 id="control-structures.break">
<title><literal>break</literal></title>
<para>
<literal>break</literal> breaks out of the current looping control-structures.
<informalexample>
<programlisting>
<simpara>
<literal>break</literal> ends execution of the current
<literal>if</literal>, <literal>for</literal>,
<literal>while</literal>, or <literal>switch</literal>
structure.
</simpara>
<simpara>
<literal>break</literal> accepts an optional numeric argument
which tells it how many nested enclosing structures are to be
broken out of.
</simpara>
<para>
<informalexample>
<programlisting>
$i = 0;
while ($i < 10) {
if ($arr[$i] == "stop") {
break;
break; /* You could also write 'break 1;' here. */
}
$i++;
}
</programlisting>
</informalexample></para></sect1>
<sect1 id="control-structures.continue">
<title><literal>continue</literal></title>
<para>
<literal>continue</literal> is used within looping structures to
skip the rest of the current loop iteration and continue
execution at the beginning of the next iteration.
/* Using the optional argument. */
$i = 0;
while ( ++$i ) {
switch ( $i ) {
case 5:
echo "At 5&lt;br&gt;\n";
break 1; /* Exit only the switch. */
case 10:
echo "At 10; quitting&lt;br&gt;\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.continue">
<title><literal>continue</literal></title>
<simpara>
<literal>continue</literal> is used within looping structures to
skip the rest of the current loop iteration and continue execution
at the beginning of the next iteration.
</simpara>
<simpara>
<literal>continue</literal> accepts an optional numeric argument
which tells it how many levels of enclosing loops it should skip
to the end of.
</simpara>
<para>
<informalexample>
<programlisting>
while (list($key,$value) = each($arr)) {
if ($key % 2) { // skip even members
continue;
}
do_something_odd ($value);
}
</programlisting>
</informalexample></para></sect1>
while (list($key,$value) = each($arr)) {
if ($key % 2) { // skip even members
continue;
}
do_something_odd ($value);
}
$i = 0;
while ( $i++ &lt; 5 ) {
echo "Outer&lt;br&gt;\n";
while ( 1 ) {
echo "&nbsp;&nbsp;Middle&lt;br&gt;\n";
while ( 1 ) {
echo "&nbsp;&nbsp;Inner&lt;br&gt;\n";
continue 3;
}
echo "This never gets output.&lt;br&gt;\n";
}
echo "Neither does this.&lt;br&gt;\n";
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.switch">
<title><literal>switch</literal></title>