home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / modula2 / 1041 next >
Encoding:
Internet Message Format  |  1992-08-23  |  3.0 KB

  1. Path: sparky!uunet!uunet.ca!geac!r-node!bville!greg.vigneault
  2. From: greg.vigneault@bville.gts.org (Greg Vigneault) 
  3. Newsgroups: comp.lang.modula2
  4. Subject: CODE! PLEASE!
  5. Message-ID: <80.492.uupcb@bville.gts.org>
  6. Date: 23 Aug 92 11:09:00 GMT
  7. Distribution: world
  8. Organization: Baudeville BBS - Toronto, Canada 416-283-0114/6059* *v32bis/HST
  9. Reply-To: greg.vigneault@bville.gts.org (Greg Vigneault) 
  10. Lines: 75
  11.  
  12.  In message-ID <16937.2A8EC01C@puddle.fidonet.org>
  13.  Subj: CODE! PLEASE!
  14.  Jai.Braatz@p1.f401.n208.z1.fidonet.org (Jai Braatz) writes...
  15.  
  16. JB> I've asked this here several times before, and I seem to never
  17.   > get a response.  Is it my end? Can someone post small but
  18.   > complete pieces of Modula-2 code (like a hello world program
  19.   > and something that reads in numbers from a file or something)
  20.   > for me to look at as an example? PLEASE?
  21.  
  22. (*****************************************************************)
  23.  MODULE Hello;
  24.  
  25.  FROM InOut     IMPORT  WriteCard, WriteLn, WriteString;
  26.  
  27.  VAR  loopc     : CARDINAL;
  28.       anystring : ARRAY [0..16] OF CHAR;
  29.  
  30.  BEGIN
  31.         anystring := " world!"; (* string assignment             *)
  32.  
  33.         FOR loopc := 1 TO 20    (* write the string 20 times     *)
  34.             DO
  35.                 WriteCard( loopc, 2 );      (* loop count        *)
  36.                 WriteString( " Hello," );   (* a string constant *)
  37.                 WriteString( anystring );   (* a string variable *)
  38.                 WriteLn;                    (* new line          *)
  39.             END;
  40.         (* do it 20 more times, using WHILE                      *)
  41.         WHILE ( loopc > 0 )
  42.             DO
  43.                 WriteCard( loopc, 2 );      (* loop count        *)
  44.                 WriteString( " Hello," );   (* a string constant *)
  45.                 WriteString( anystring );   (* a string variable *)
  46.                 WriteLn;                    (* new line          *)
  47.                 DEC( loopc );               (* count down        *)
  48.             END;
  49.  END Hello.
  50. (*****************************************************************)
  51.  
  52.  
  53. (*****************************************************************)
  54.  MODULE ReadNumber;
  55.  
  56.  FROM InOut     IMPORT  ReadCard, Write, WriteCard,
  57.                         WriteLn, WriteString;
  58.  
  59.  VAR  aCard, loopc  : CARDINAL;
  60.  
  61.  BEGIN
  62.         loopc := 1;
  63.         REPEAT
  64.             WriteString( "Enter a number (99..199): " );
  65.             ReadCard( aCard );
  66.             WriteLn;
  67.             INC( loopc );
  68.         UNTIL (aCard >= 99) AND (aCard <= 199) OR (loopc > 5);
  69.  
  70.         IF (loopc > 5)     (* 5 unsuccessful tries? *)
  71.             THEN
  72.                 WriteString( "You failed the 99..199 test!" );
  73.                 Write( 7C );    (* beep *)
  74.             ELSE
  75.                 WriteString( "Thanks, you entered " );
  76.                 WriteCard( aCard, 1 );
  77.                 WriteLn;
  78.             END;
  79.  
  80.  END ReadNumber.
  81. (*****************************************************************)
  82.  
  83.  Greg_
  84.  
  85.  Aug.23.1992.Toronto.Canada.        greg.vigneault@bville.gts.org
  86.                                                                                   
  87.