program CountWords;
var
str: string;
i, wordCount: Integer;
inWord: Boolean;
begin
str := 'Pascal is an imperative and procedural programming language';
wordCount := 0;
inWord := False;
for i := 1 to Length(str) do
begin
if str[i] <> ' ' then
begin
if not inWord then
begin
inWord := True;
Inc(wordCount);
end;
end
else
inWord := False;
end;
WriteLn('Word count: ', wordCount);
end.
(*
run:
Word count: 8
*)