! Example program: compute and print the first MAX prime numbers.
! Compile with 'tx primes.t'

sieve() do
	const	MAX=1000;
	var	primes[MAX];
	var	i, p, top, ok;

	primes[0] := 2;
	writes("       2"); newline();
	top := 1;
	p := 3;
	while (top<MAX) do
		ok := 1;
		for (i=0,top) do
			if (\(p mod primes[i])) do
				ok := 0;
				leave;
			end
		end
		if (ok) do
			writes(ntoa(p, 8)); newline();
			primes[top] := p;
			top := top+1;
		end
		p := p+2;
	end
end

do
	sieve();
end
