Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Absolute need of goto 4 correct functioning of loop routine.
#20
Hi meg.

I am *not* a goto proponant. However, I've found it useful in this program, which I think is a reasonable way to program a small prime number calculator.



Code:
defint a-z
DIM SmallPrimes(1 to 3500) AS INTEGER

CLS
PRINT "This program sticks primes in an array then prints 'em"

'set initial values
a = 0
max = 3
smallprimes(1) = 3
next1 = 5
count = 1

'find first 3500 primes and put them in array, smallprimes()
'use 2-byte integer for small primes
DO WHILE count < 3500
  sqroot = SQR(next1)

  DO
      a = a + 1
      IF next1 MOD smallprimes(a) = 0 THEN GOTO notprime
  LOOP WHILE sqroot > smallprimes(a)

  count = count + 1
  smallprimes(count) = next1

notprime:

  next1 = next1 + 2
  a = 0
LOOP


FOR z = 1 TO 3500
   PRINT smallprimes(z);
NEXT z
Reply


Messages In This Thread
Need more - by Mac - 02-03-2005, 12:50 AM
Mea culpa - by Mac - 02-03-2005, 01:57 AM
Using goto - by Mango - 02-12-2005, 04:45 PM
Not required though - by Mac - 02-12-2005, 07:55 PM
Got UnLazy - by Mac - 02-12-2005, 11:12 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)