[Javascript] Generating Prime Numbers

dougwris dougwris at swbell.net
Sun Jan 5 21:29:52 CST 2003


I've written many modest scripts, but this one baffles me.  It generates all the prime numbers under 2000.  Can anyone explain it to me? 
Thx, Doug.


<script>
<!--
for (i=2; i<=100; i++) { 
        if (i%100==0){document.write("<BR>")}; 
 prime=true; 
 for (j=2; j<i; j++) { 
            if (i%j==0){prime=false;break} 
        }; 
 if (prime){document.write(i+" ")}; 
}
//-->
</script>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030105/1d3c23ee/attachment.htm>


More information about the Javascript mailing list