2008-12-27 01:35:49 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:17:58 +00:00
|
|
|
<!-- $Revision$ -->
|
2008-12-27 01:35:49 +00:00
|
|
|
|
|
|
|
<sect1 xml:id="control-structures.break" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
2020-12-06 22:38:36 +00:00
|
|
|
<title>break</title>
|
2011-07-05 18:59:24 +00:00
|
|
|
<?phpdoc print-version-for="break"?>
|
2008-12-27 01:35:49 +00:00
|
|
|
<simpara>
|
|
|
|
<literal>break</literal> ends execution of the current
|
|
|
|
<literal>for</literal>, <literal>foreach</literal>,
|
|
|
|
<literal>while</literal>, <literal>do-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
|
2015-06-27 20:25:03 +00:00
|
|
|
broken out of. The default value is <literal>1</literal>, only
|
2015-06-27 22:32:48 +00:00
|
|
|
the immediate enclosing structure is broken out of.
|
2008-12-27 01:35:49 +00:00
|
|
|
</simpara>
|
|
|
|
<para>
|
|
|
|
<informalexample>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$arr = array('one', 'two', 'three', 'four', 'stop', 'five');
|
2018-07-27 10:52:29 +00:00
|
|
|
foreach ($arr as $val) {
|
2008-12-27 01:35:49 +00:00
|
|
|
if ($val == 'stop') {
|
|
|
|
break; /* You could also write 'break 1;' here. */
|
|
|
|
}
|
|
|
|
echo "$val<br />\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Using the optional argument. */
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while (++$i) {
|
|
|
|
switch ($i) {
|
2018-06-08 11:20:15 +00:00
|
|
|
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;
|
2008-12-27 01:35:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</informalexample>
|
|
|
|
</para>
|
2020-10-31 19:13:58 +00:00
|
|
|
|
2008-12-27 01:35:49 +00:00
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2008-12-27 01:35:49 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|