note 108865 deleted from control-structures.continue by danbrown
| From: | danbrown@php.net | Date: | Thu, 31 May 2012 16:48:35 +0000 |
| Subject: | note 108865 deleted from control-structures.continue by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188344@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
/* Improvement to the previous example would be to only check if the number is divisible by less
than half of its value (because a number 'x' can never be divisible by a number
'y' that is more than its half) */
<?php
function print_primes_between($x,$y)
{
for($i=$x;$i<=$y;$i++)
{
for($j= 2; $j < ($i/2); $j++) if($i%$j==0) //Check divisibility less than only half of
the number
continue 2;
if($i!=0 && $i!=1) //0&1 not included in prime numbers
echo $i.",";
}
}
echo print_primes_between(0,50);
?>