mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
a80e9af9ab
commit
2ae0853180
1 changed files with 80 additions and 26 deletions
|
@ -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<br>\n";
|
||||
break 1; /* Exit only the switch. */
|
||||
case 10:
|
||||
echo "At 10; quitting<br>\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++ < 5 ) {
|
||||
echo "Outer<br>\n";
|
||||
while ( 1 ) {
|
||||
echo " Middle<br>\n";
|
||||
while ( 1 ) {
|
||||
echo " Inner<br>\n";
|
||||
continue 3;
|
||||
}
|
||||
echo "This never gets output.<br>\n";
|
||||
}
|
||||
echo "Neither does this.<br>\n";
|
||||
}
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1 id="control-structures.switch">
|
||||
<title><literal>switch</literal></title>
|
||||
|
||||
|
|
Loading…
Reference in a new issue