home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 666 / h3.hlp < prev    next >
Text File  |  1992-12-05  |  6KB  |  154 lines

  1.  
  2.                             STATEMENTS
  3.  
  4. left-hand-value = expr ;       simple assignment, map update,
  5. if ( expr ) stat1              conditional statement - form1
  6. if ( expr ) stat1 ;            conditional statement - form2
  7.    else stat2
  8. while ( expr ) stat            while statement
  9. for iden <- expr ; stat        for statament
  10. return ;                       return statement - form1
  11. return expr;                   return statement - form2
  12. iden ( expr-list );            function call
  13. { stat1 ; ... statn ; }        block
  14. open(iden,"r") ;               open read statement
  15. open(iden,"w") ;               open write statement
  16. close(iden) ;                  close statement
  17. readln(v1,...,vn) ;            readln statement
  18. readln(iden,v1,...vn) ;        readln file statement
  19. writeln(v1,...,vn) ;           writeln statement
  20. writeln(iden,v1,...,vn) ;      writeln file statement
  21.  
  22. A statement is either a simple statement or a block (see below),
  23. which is a sequence of statements delimited by curly brackets.
  24.  
  25. Assignment Statement
  26.  
  27. identifier = expression ;       expression is evaluated and the
  28.                                 resulting value is stored in
  29.                                 identifier. Examples are:
  30.  
  31. x = {2, 3, 5, 7} ;              simple assignment
  32. m["Joe"] = 30;                  map update
  33. p.r = {1->2, 3->4};             struct update
  34.  
  35. Conditional Statement
  36.  
  37. The conditional or if-statement may take one of the following
  38. forms:
  39.  
  40. if ( expr ) stat1                  in both cases, expr is evaluated;
  41.                                    if it evaluates to true then stat1
  42. if ( expr ) stat1 ; else stat2     is executed. If it evaluates to
  43.                                    false, in the first case nothing
  44.                                    happens; in the second case stat2
  45.                                    is executed. Examples are:
  46.  
  47. if (x < 2) y = 0;
  48. if (n == 0 ) f = 1; else f = n * f;
  49.  
  50. While statement
  51.  
  52. while ( expr ) stat                expr is evaluated; as long as its
  53.                                    value is true, stat is executed,
  54.                                    and expr is reevaluated; when its
  55.                                    value is false, the following
  56.                                    statement is executed. Example:
  57.  
  58. while (n <= 10) n=n+1;
  59.  
  60. For statement
  61.  
  62. for identifier <- expr ; stat      expr is evaluated and identifier
  63.                                    is assigned the values of the
  64.                                    resulting set or sequence; stat
  65.                                    is executed for each of these
  66.                                    assignments. Example:
  67.  
  68. for i <- {1..10}; writeln(i);
  69.  
  70.  
  71. Return statement
  72.  
  73. The return statement may take one of the following forms:
  74.  
  75. return ;                           the enclosing function is terminated.
  76.  
  77. return expr ;                      expr is evaluated and the enclosing
  78.                                    function is terminated with the value
  79.                                    of expr as its returned value. Example
  80.  
  81. return n+1;
  82.  
  83. I/O statements:
  84.  
  85. open(string,"r");                  Opens a file for reading given by
  86.                                    string, and returns a file handle.
  87.  
  88. h = open("data.txt","r");
  89.  
  90. open(string,"w") ;                 Opens a file for writing given by
  91.                                    string, and returns a file handle.
  92.  
  93. close(identifier) ;                Closes the file whose handle is
  94.                                    given by identifier.
  95.  
  96. close(h);
  97.  
  98. writeln(v1,...,vn) ;               The scalar values or scalar valued
  99.                                    variables vi (integer, real, string,
  100.                                    boolean) are printed on one line
  101.                                    separated by spaces.
  102.  
  103. writeln(123,r,"order");
  104.  
  105. writeln(identifier,v1,...,vn) ;    The values v1,...vn are output to
  106.                                    the file whose handle is given by
  107.                                    identifier.
  108.  
  109. writeln(h,123,r,"order");
  110.  
  111. readln(v1,...,vn) ;                The variables v1,...vn (which must be
  112.                                    global) are assigned the corresponding
  113.                                    values input at the keyboard.
  114.  
  115. readln(a,b,c);
  116.  
  117. readln(identifier,v1,...vn) ;      The variables v1,...vn are assigned
  118.                                    the corresponding values in the file
  119.                                    whose handle is given by identifier.
  120.                                    If there are no more values in the file
  121.                                    to read, the global variable eof has
  122.                                    the value true, otherwise it has the
  123.                                    value false.
  124.  
  125. fun() {readln(h,a,b,c);
  126.        while(!eof) {writeln(a,b,c);
  127.                     readln(h,a,b,c);}
  128.       };
  129.  
  130. Function  call
  131.  
  132. identifier ( expr-list ) ;         Each expr in expr-list is evaluated
  133.                                    and the function represented by
  134.                                    identifier is called with the
  135.                                    resulting arguments. If the function
  136.                                    call is not contained in an expression
  137.                                    i.e. it appears in a statement
  138.                                    context, the resulting value is
  139.                                    discarded.
  140.  
  141. Block
  142.  
  143. A sequence of statements may be grouped together to form a block
  144. by enclosing them within curly brackets:
  145.  
  146. { stat1 ;
  147.   stat2 ;
  148.   ...
  149.   statn ;
  150. }                                  Notice that there is no semi-colon
  151.                                    after the closing bracket. Example:
  152.  
  153. while (bal>0) {int=bal*r;am=pay-int;bal=bal-am;n=n+1;}
  154.