% Read and echo names; count them; check for uniqueness

const N: int := 50	% maximum names
var i, count, dups : int := 0
var found : boolean
var names : array 1 .. N of string

put "Please type a series of names."
put "Tell me 'quit' at the end"

loop
	put "Next name? " ..
	var person : string
	get person
	exit when person = "quit" or i > N

%	OK, so a name has been entered.  Let's see if it's
%	already in the list.  This is called a "linear" search,
%	because we're looking at each item in sequence.

	found := false
	i := 0;
	loop  % is person on the list already?
		exit when found or i = count
		i := i + 1
		found :=  (person = names(i))
	end loop

	if found then
		put "You know, there's already a ",
			person, " on this list,"
		put "so I won't say hello to you again."
		dups := dups + 1
	else
		count := count + 1
		names(count) := person
		put "Hi, ", person, ".  I've added you to ",
		     "my list at position ", count
	end if
end loop
put "I greeted ", count, " people," 
put "and there were ", dups, " duplicate names entered."
