Home  >  Article  >  Backend Development  >  用一个函数获取质数的纳闷

用一个函数获取质数的纳闷

WBOY
WBOYOriginal
2016-06-13 11:36:26664browse

用一个函数获取质数的疑惑


// 获取100—200之间的素数
function main()
{
for($i=100; $i<201; $i++){
$b = false;
for($j=2; $j<$i-1; $j++){
$k = $i % $j;
if($k == 0){
$b = true;
//break;
}
}
if(!$b){
echo $i ."
";
}
}
}

// 我的疑虑在break那个地方,测试最后的结果,有没有break,都是一样的结果。
// 但如果要用程序来解释数学定义,就得加上break对吧?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn