Skip to content

Instantly share code, notes, and snippets.

@LukeAims
Created April 3, 2019 22:45
Show Gist options
  • Save LukeAims/9f58ab1a7e9e6399123814eb177d089f to your computer and use it in GitHub Desktop.
Save LukeAims/9f58ab1a7e9e6399123814eb177d089f to your computer and use it in GitHub Desktop.
// number > 1 is a prime if it can’t be evenly divided by anything except 1 and n.
// define var n
let n = 1000;
nextPrime:
for (let i = 2; i <= n; i++) { // for each i do...
for (let j = 2; j < i; j++) { // look for a divisor..
if (i % j == 0) continue nextPrime; // not a prime, go next i
}
console.log( i ); // a prime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment