Core Function Break

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(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...")
 
(Example)
Line 43: Line 43:
 
     switch ($i)  
 
     switch ($i)  
 
     {
 
     {
        case 5:
+
    case 5:
 
         echo "At 5\n";
 
         echo "At 5\n";
 
         break 1;  /* Exit only the switch. */
 
         break 1;  /* Exit only the switch. */

Revision as of 04:36, 23 September 2013

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