VBScript

VBScript is essentially the same language as Visual Basic. There are no variable declarations except for arrays, variables do not have types, and the Next statement must be bare, with no variable name.

This code compiles and executes under Internet Explorer 7.0, and will probably execute correctly under most modern web browsers. Click the link below to execute the code. To see the source code, stay on the results screen and right-click. Select "View Source" and the source code will apppear in the notepad.

<html> <head> <title>VBscript Sourcecode</title> </head> <body> <h1>VBscript Sourcecode</h1> <h2>Right-Click and select "View Source" to see source code.</h2> <p> <script type="text/vbscript"> '/ define the sieve data structure Dim Candidates(1000) For i = 0 To 999 '/ everything is potentially prime until proven otherwise Candidates(i) = 1 Next '/ Neither 1 nor 0 is prime, so flag them off Candidates(0) = 0 Candidates(1) = 0 '/ start the sieve with the integer 0 i = 0 While i < 1000 '/ advance to the next un-crossed out number. '/ this number must be a prime While i < 1000 And Candidates(i) = 0 i = i + 1 Wend '/ insure against running off the end of the data structure If i < 1000 Then '/ cross out all multiples of the prime, starting with 2*p. j = 2 While j * i < 1000 Candidates(j * i) = 0 j = j + 1 Wend '/ advance to the next candidate i = i + 1 End If Wend '/ all uncrossed-out numbers are prime (and only those numbers) '/ print all primes For i = 0 To 999 If Candidates(i) <> 0 Then document.write( i ) document.write( " is prime<br>" ) End If Next </script> </body> </html>

Click Here for the actual code.