home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / clnclp.zip / SAMPLE.PRG < prev    next >
Text File  |  1993-11-01  |  2KB  |  75 lines

  1. /* This is a Clipper program for testing CleanClipper V1.0
  2. */
  3.  
  4. function main()
  5.  
  6. LOCAL m, a, b, c, d, e, f, g
  7. strg := "abcdefghijklmnopqrstuvwxyz"&& this is a test
  8.  
  9. * code block spacing example
  10. local myblock :={|a,b |a<b }
  11.  
  12. // loop invariant P0 == 0<=m<3 and alphabet written m*2 times thus far
  13.   m:= 0         // P0 true
  14.  scroll()
  15.   do WHILE m !=3 
  16.         display(m,str) /* call display for writing str */
  17.         m++    && add 1 to m => P0 true
  18.   Enddo  // finished with loop
  19.  
  20.   // assignment examples to demstrate minimizing/maximizing parentheses
  21.   m:= a.and.b .OR. d.and.e<3 .And. f!=g
  22.   m := (a.and.b) .or. (d.AND.(e>3) .and. (f!=g))  // same as above but with parens
  23. RETURN nil
  24.     
  25.  
  26. FUNCTION display(m, s)
  27.  
  28. /* Pre-cond : 0<=m<3 && s = string of alphabet
  29. *  Post-cond: string s written diagonally twice
  30. */
  31.  
  32.   local r, c
  33.   * demonstrate "if" constructs
  34.   if m == 0        // check value of m
  35.      c := 0
  36.   ELSEIF m == 1
  37.     c := 10
  38.   else
  39.       c := 20 
  40.   ENDIF       && c = 0, 10 or 20 depending on m 
  41.   
  42.  
  43.   // demonstrates "for" constructs
  44.   FOR r = 1 to 25
  45.    @ r, c say s[r]
  46.    c++
  47.   next
  48.  
  49.   * another demonstration of "if" construct
  50.   IF m == 0 
  51.      c := 5
  52.   elseif m == 1
  53.    c := 15
  54.   else
  55.     c := 25
  56.  Endif                /* c = 5, 15 or 25 depending on m */
  57.  
  58.   // demonstrates of "case" construct
  59.   DO CASE
  60.    case m == 0
  61.    c:= 5
  62.    CASE m==1 .or.m==2
  63.      c:=15
  64.      OTHERWISE
  65.       c:=25
  66.    endcase
  67.  
  68.   // demonstrates "while" construct
  69.   r := 0
  70.   do WHILE r !=25           && loop until r=25
  71.      @ r,c say s[r]   /* position cursor for display */
  72.   c:=c+1  /* print character */
  73.   ENDDO
  74. return nil
  75.