note 77272 added to control-structures.break
| From: | Gautam at osu1 dot php dot net | Date: | Wed, 22 Aug 2007 09:53:40 +0000 |
| Subject: | note 77272 added to control-structures.break | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129695@lists.php.net to get a copy of this message | ||
<?php
/*
break :break command exits the innermost loop construct which contains it.
break ends execution of the current for, foreach, while, do-while or switch structure.
break accepts an optional numeric argument which tells it how many nested enclosing structures are
to be broken out of.
You can view various output by changing comparision operator(<,==,>) or value of $limit
*/
$to_square_root=65536;
$i=1;
$limit=4;
while (true) {
$square_root=sqrt($to_square_root);
echo "Square Root of $to_square_root is $square_root.<BR>";
$to_square_root=$square_root;
$i=$i+1;
if ($i>$limit) // if ($i<$limit) is used, loop breaks on very first execution
break;
}
$loop=$i-1;
echo "This loop is executes for $loop times.";
/* Above codes produces following output in browser
Square Root of 65536 is 256
Square Root of 256 is 16
Square Root of 16 is 4
Square Root of 4 is 2
This loop is executes for 4 times
*/
?>
----
Server IP: 216.235.15.211
Probable Submitter: 64.187.5.111
----
Manual Page -- http://www.php.net/manual/en/control-structures.break.php
Edit -- https://master.php.net/note/edit/77272
Del: integrated -- https://master.php.net/note/delete/77272/integrated
Del: useless -- https://master.php.net/note/delete/77272/useless
Del: bad code -- https://master.php.net/note/delete/77272/bad+code
Del: spam -- https://master.php.net/note/delete/77272/spam
Del: non-english -- https://master.php.net/note/delete/77272/non-english
Del: in docs -- https://master.php.net/note/delete/77272/in+docs
Del: other reasons-- https://master.php.net/note/delete/77272
Reject -- https://master.php.net/note/reject/77272
Search -- https://master.php.net/manage/user-notes.php