How to find all prime numbers within 200 without using functions.
Because I haven’t talked about functions in class yet, but there is this question in my homework
PHPz2017-05-19 10:31:40
var sum=0;
for(var i=2;i<200;i++){
var count=0;
for(var j=2;j<i;j++){
if(i%j==0){
count++;
}
}
if(count==0){
console.log(i);//质数
sum++;
}
}
console.log(sum);//总数
淡淡烟草味2017-05-19 10:31:40
for (let i = 1; i <= 200; i++) {
let flag = 1;
while (flag) {
if (i % flag === 0 && flag !== 1 && flag !== i) {
flag = false;
}
if (flag === i) {
flag = false;
console.log(i)
}
flag = flag ? flag + 1 : false;
}
}