84.7 Sample Input File Showing Major MPPL Features

 
  #LOOPING CONSTRUCTS
  #
  define N 100
  define M  20
     function shoot(j)
  c This subroutine shows the six different looping constructs
     real xx(N),y(M),x,y
  # there are four kinds of DO loops plus WHILE and FOR loops.
  #

  # TRADITIONAL LABELED DO LOOP
     do 100 i=1,10
          if(x(i) = 4) then
               break         # same as go to next stmt after 100
          endif
          if(x(i) = 5 then
               next # same as go to loop label (100)
          endif
  100          y(2) = x(i)         # this gets executed on a next
  #

  # DO LOOPS WITHOUT LABELS
  # next gets you to next iteration; break gets you out
  # SIMPLE LOOP
  #
     do i=1,M
          if(y(i) < 0) break
          if(y(i) >= 10.) next
          y(i) = sqrt(10.-y(i))
     enddo
  #

  # NESTED LOOPS
  #
     do i = 1,M
          do j = 1,N
               if(x.eq.10)then #next iteration of inner loop
                    next
               endif
               if(x.eq.20)then #next iteration of outer loop
                    next(2)
               endif
               xx(j) = 8
               if(y(i) > x(j))then
                    break     # get out of inner loop
               else
                    break(2)  # get out of inner loop
               endif
          enddo j   # end inner loop
                    # ignores anything after enddo
     enddo i            # end outer loop
  #

  # DO FOREVER
  # repeats forever; get out with break, return, or goto.
  #
     i=0
     do
          i = i + 1
          if(i > M) break
          if(x(i) == 32)
               next
          x(i)=1/(x(i)-32)
     enddo
  #

  # WHILE/ENDWHILE
  # does a loop as long as the condition is satisfied
  #
     i = N
     while(x(i)-x(i+1) > 1.e-5 & i <> 0)   #&=.and.  <>=.ne.
          i = i - 1
     endwhile
  #

  # DO/UNTIL
  # repeats until the condition is satisfied. Note that unlike
  # a while loop, the loop body is always done once
  #
     do
          i = i - 1
          if(i = 0 | x(i) <= 0.) break        # | = .or.
     until(x(i)-x(i+1) < 1.e-3)
  #

  # FOR/ENDFOR
  # has three arguments separated by commas:
  # a) initialization statements to be executed before the
  # loop, b) the condition under which the loop is to be
  # executed while true, and c) the reinitialization
  # statements to be executed at the start of each loop after
  # the first before the condition is tested. The condition,
  # argument 2, must be present; other arguments are optional.
  #
  # The following example is the same as do i=1,N;x(i)=i;enddo
  #
     for (i-1, i<=N, i=i+1)
          x(i) = 1
     endfor
  #
  # FOR loops are good for things DO LOOPS can't do:
  # the hard way to find the square root of two is:
  #
     for(t = 1.,abs(t**2 - 2.) > 1.e-6, t=(t+2./t)/2.)
     endfor
  #

  # FUNCTIONS
  # The return statement can have an argument to give the
  # returned value.
  #
     return(t)
     end
     real function boxo(w,z)
     real w,z,a,b
  #

  # IF STATEMENTS
  # There are two basic kinds of IF; this routine shows some
  # of the variations allowed.
  #
  # IF(CONDITION) THEN ...ENDIF
  #
     if( a<b)            #ok if then is on next line
     then
          call odd("this is a string; try it");return(b-a)
     endif
     if(a <> b) then         #if a .ne. b
          x = y
     else if (b > a-1)         #ok if you forget the then here
          x=y/2 +         #statements continued if they end
          golf(tango,         #in +,-,*,comma,=,(,&,|,caret, or
          bravo \         #backslash; backslash is deleted
          -1)
          y="This is a quoted string "" with a quote in it\"
                         #...but not inside strings
     else if("the sky is blue >")then #or put in to be neat
          howdy = 1
     else
          if(a == w) call junko
     endif
  #

  # IF(CONDITION)STATEMENT/RETURN(VALUE)
  # is correct even if it expands to more than one statement.
  #
     if(a > b)
          b = b/2
     if( a<> b) return(gas)
     return(bug)
     end
     program testme
  #

  # SELECT/CASE/DEFAULT/ENDSELECT
  # You can put things after an ENDDO that are ignored.
  #
     real x(N)
     do i=1,10
          x(i) = i - 1
     enddo i --end of loop setting initial values for x
  #
  # You can have multiple statements by separating them
  # with semicolons, even in the arguments of a FOR statement.
  #
     i0 = 0 ; j0 = M
     for( i = i0; j = j0 , j < 9 , i=i+1;j=j-1)
          x(i) = y(j)
          for(k=j, k<i+5 , k=k+1)
               z(k) = y(j) + x(i)
          endfor
     endfor
  #

  # SELECT allows you to test an integer variable against
  # different cases.
  #
     select(j)
     case 5: y=5         #if j is 5 do these two statements
          z = 4                 ! exclamation points are also comments
     case 6: y=6         ! if j is 6 do this one
     case 7,8,10:         ! statements can follow on next line
          y=8;z=4         ! if j is 7, 8, or 10
     case 11-20,9: y=9         #if j is between 11 and 20
                         #inclusive or is 9
     default:
          y=0                 #do if j is none of the above
     endselect
  #
     call exit
     end