Core Function Break

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(One intermediate revision by one user not shown)

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;
    }
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox