Use a function to obtain the question of Prime Number // & nbsp; obtain the prime number function & nbsp; main () {for ($ I = 100; & nbsp; $ I & lt; 201; & nbsp; $ I ++) {$ B & nbsp ;=& nbsp; false; for questions about getting prime numbers using a function
// Obtain the prime number between and
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 ."
";
}
}
}
// My doubts are at the break location. The final result of the test is the same if there is any break.
// But if you want to use a program to explain the mathematical definition, you have to add break, right?
Share:
------ Solution --------------------
Whether or not break does not affect the print result, because the print condition is the $ I prime number.
But for operational efficiency, when there is no break, it needs to be relatively complete data ($ i-1) to end, and when there is break, it ends when the first sum is found, the subsequent ineffective work will not have to be done again.
------ Solution --------------------
Reference:
Whether or not break does not affect the print result, because the print condition is the $ I prime number.
But for operational efficiency, when there is no break, it needs to be relatively complete data ($ i-1) to end, and when there is break, it ends when the first sum is found, the subsequent ineffective work will not have to be done again.
+ 1
When you try to calculate a prime number within 20000 or greater, you will know the difference between a break and a non-break. you might as well test it.