Core Function Break
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> Break( <scopes> ) </pre> === Description === Ends execution of the current loop. ==== scopes ==== Optional; Tell it how many nested enclosing structures are to be brok...") |
m (1 revision) |
||
(2 intermediate revisions by one user not shown) | |||
Line 43: | Line 43: | ||
switch ($i) | switch ($i) | ||
{ | { | ||
− | + | case 5: | |
echo "At 5\n"; | echo "At 5\n"; | ||
break 1; /* Exit only the switch. */ | break 1; /* Exit only the switch. */ |
Latest revision as of 12:37, 14 June 2015
Break( <scopes> )
Contents |
Description
Ends execution of the current loop.
scopes
Optional; Tell it how many nested enclosing structures are to be broken out of.
Return Value
None.
Remarks
N/A
Example
Example of breaking out of a loop
$arr = array('one', 'two', 'three', 'four', 'stop', 'five'); while (list($key, *$value) = each($arr)) { if ($value == 'stop') { break; /* You could also write 'break 1;' here. */ } echo "$value\n"; }
Example of using the optional argument
$i = 0; while (++$i) { switch ($i) { case 5: echo "At 5\n"; break 1; /* Exit only the switch. */ case 10: echo "At 10; quitting\n"; break 2; /* Exit the switch and the while. */ default: echo "Tick...\n"; break; } }