Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

prime numbers using for loop in Js

// range = 1 o 20 
for(let number=2 ; number<=20; number++){
    let isPrime = true;

for (let i=2; i<= number-1;i++){
    if(number%i===0){
        isPrime = false;
        break
    }
}
if (isPrime) console.log(number);
}
// result = 2,3,5,7,11,13,17,19
 
PREVIOUS NEXT
Tagged: #prime #numbers #loop #Js
ADD COMMENT
Topic
Name
3+1 =