Core Function Break

From Sputnik Wiki
Jump to: navigation, search
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