Just as every true computer scientist was supposed to *hate* COBOL, every
true computer scientist was supposed to *love* Pascal.

I like Pascal OK, but there are a few things about it that are just plain stupid. Let me go through them one by one.

This makes stuff like WHILE X<1000 AND A[1000] = 0 DO just about impossible to write without making A one larger than necessary. Idiotic.

This is mathematical nonsense. AND and OR are symmetric and interchangable with one another. Also it makes the following statment syntactically incorrect.

IF A < B AND C < D THEN

This is syntactically incorrect because multiplying operators bind tighter than comparison operators so this self-parenthesizes like this:

IF A < (B AND C) < D THEN

OK, I admit it. This one is just personal prejudice. I once spent several hours
in the Iowa State University computer room running a Pascal program over and over
and over and over and over ... . It was an example straight out of the book. Suddenly
I realized, that what I had taken for a fly-speck on the paper was actually a period
at the end of a program and that the gobbeldey-gook coming out of the compiler was
telling me that the *only* thing wrong with my program was the missing period at the
end.

This program compiles and runs under Turbo Pascal. Turbo Pascal is now freely available on Borland's website. The Borland folks, being sensible people, changed the AND and OR semantics so that they short-circuit by default. (Otherwise this program wouldn't work.) Those who prefer the original semantics can turn them back on. They added a few other nice things too. Like objects.

We have no Delphi example on this site because Delphi is not a language but a programming system that uses Object Pascal as its base language. There are a couple of added features to support the development of components, but Delphi and Pascal are essentially the same thing.

{//////////////////////////////////////////////////////////

// Name: Peter M. Maurer

// Program: Sieve of Eratosthenes

// Due: Never

// Language: Pascal

//////////////////////////////////////////////////////////}

Program SieveE;

var Candidates : Array[0..999] of Integer;

i,j : Integer;

begin

{ define the sieve data structure }

for i := 0 to 999 do

begin

{ everything is potentially prime until proven otherwise }

Candidates[i] := 1;

end;

{ 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 do

begin

{ advance to the next un-crossed out number. }

{ this number must be a prime }

while (i<1000) and (Candidates[i] = 0) do

begin

i := i+1;

end;

{ insure against running off the end of the data structure }

if i<1000 then

begin

{ cross out all multiples of the prime, starting with 2*p. }

j := 2;

while j*i < 1000 do

begin

Candidates[j*i] := 0;

j := j+1;

end;

{ advance to the next candidate }

i := i+1;

end

end;

{ all uncrossed-out numbers are prime (and only those numbers) }

{ print all primes }

for i := 0 to 999 do

begin

if Candidates[i] <> 0 then

begin

writeln(i,' is prime');

end

end

end.