MODULE CountChars3; (* ========================================================================= Example GPCP .NET Console Program Count the number of letters and digits in a string using IF THEN ELSE statements Author : Chris Burrows Created: Jan 2007 (c) 2007-2008 CFB Software http://www.cfbsoftware.com/gpcp ========================================================================= *) IMPORT Out, CPmain; PROCEDURE WriteCount(count: INTEGER; IN msg: ARRAY OF CHAR); BEGIN Out.Int(count, 8); Out.String(msg); Out.Ln() END WriteCount; PROCEDURE CountChars(IN s: ARRAY OF CHAR); VAR i, letters, digits, others: INTEGER; ch: CHAR; BEGIN Out.String(s); Out.Ln(); letters := 0; digits := 0; others := 0; FOR i := 0 TO LEN(s$) - 1 DO ch := s[i]; IF (CAP(ch) >= 'A') & (CAP(ch) <= 'Z') THEN INC(letters) ELSIF (ch >= '0') & (ch <= '9') THEN INC(digits) ELSE INC(others) END END; WriteCount(letters, ' letters'); WriteCount(digits, ' digits'); WriteCount(others, ' others') END CountChars; BEGIN CountChars('The quick brown fox jumped over the lazy dog.'); CountChars('Digit 1 looks like letter l, and digit 0 looks like letter O.') END CountChars3.