Einlese-Schleifen

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

Minimum.om
(*
   read integers from standard input and
   print minimal value
*)
MODULE Minimum;

   IMPORT Read, Streams, Write;

   VAR
      min: INTEGER; (* minimal value seen so far *)
      mindefined: BOOLEAN; (* min well-defined? *)
      value: INTEGER; (* last input value *)

BEGIN
   mindefined := FALSE; (* min not initialized yet *)
   LOOP
      Read.Int(value); (* try to read a value *)
      IF Streams.stdin.count = 0 THEN EXIT END;
      (* value is well-defined now *)
      IF ~mindefined OR (value < min) THEN
         (* new minimum found *)
         min := value; mindefined := TRUE;
      END;
   END;
   IF mindefined THEN
      Write.Int(min, 1); Write.Ln;
   END;
END Minimum.

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 2004, 2005 Andreas Borchert, in HTML konvertiert am 18.02.2005