I have just created a prime number finder with a for loop that runs over time. Right now its at 167899 and growing every second.
What is the max number of loops a for loop can go through??? If its an ungodly big number I don't want to be waiting all night to see what is the max prime number I can generate.
Is it infinite?
Here is my code:
var isNotPrime = false;
var currentNumber = 3;
var primeArray = [2];
function prime(){
isNotPrime = false;
for(a=0; a<primeArray.length; a++){
if(currentNumber%primeArray[a] === 0){
isNotPrime = true;
}
if(a===(primeArray.length-1) && isNotPrime ===false){
document.write(currentNumber+"<BR>");
primeArray.push(currentNumber);
}
if(a===(primeArray.length-1)){
currentNumber++;
}
}
}
var main = setInterval(prime, 1);
window.alert("Starting search for Prime Numbers!");