Last active
May 28, 2021 20:39
-
-
Save jamiejohnsonkc/a40df074721c36e9a4ed2ccdfca2fb71 to your computer and use it in GitHub Desktop.
js loop output prime numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For each i in the interval { | |
// check if i has a divisor from 1..i | |
// if yes => the value is not a prime | |
// if no => the value is a prime, show it | |
// } | |
let n = 10; | |
nextPrime: | |
for (let i = 2; i <= n; i++) { // for each i... | |
for (let j = 2; j < i; j++) { // look for a divisor.. | |
if (i % j == 0) continue nextPrime; // not a prime, go next i | |
} | |
alert( i ); // a prime | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment