next up previous
Next: Comments Up: The pseudocode Environment Previous: The repeat-until Loop

Main Programs and Procedures

We can describe a main program that calls one (or more) procedures as follows:

\begin{pseudocode}{<Name>}{<Parameters>}
\PROCEDURE{<ProcedureName>}{<ProcedureParameters>}
   some stuff
\ENDPROCEDURE
\MAIN
  some stuff\\
  \CALL{<ProcedureName>}{<ActualParameters}>\\
  more stuff
\ENDMAIN
\end{pseudocode}

Here is a simple example to illustrate the use of a main program calling a procedure. The commands

\begin{pseudocode}{TemperatureTable}{lower, upper}
\PROCEDURE{CelsiusToFahrenheit}{c}
  f \GETS {9c/5} + 32\\
  \RETURN{f}
\ENDPROCEDURE 
\MAIN
x \GETS lower \\
\WHILE x \leq upper \DO
\BEGIN
 \OUTPUT{x, \CALL{CelsiusToFahrenheit}{x}}\\
 x \GETS x+1
\END
\ENDMAIN
\end{pseudocode}

produce the following output:


\begin{pseudocode}{TemperatureTable}{lower, upper}
\PROCEDURE{CelsiusToFahrenhei...
...x, \CALL{CelsiusToFahrenheit}{x}}\\
x \GETS x+1
\END
\ENDMAIN
\end{pseudocode}



Donald L. Kreher
2000-02-18