Reviewing the Sample Program for Selecting the Printer Type at Runtime

In the following example, the PROGRAM section prompts the user to select the printer type at runtime. The relevant lines are shown like this:

begin-program
  input $p 'Printer type'    ! Prompt user for printer type
  let $p = lower($p)         ! Convert type to lowercase
  evaluate $p                ! Case statement
  when = 'hp'
  when = 'hplaserjet'        ! HP LaserJet
    use-printer-type hp
    break
  when = 'lp'
  when = 'lineprinter'       ! Line Printeruse-printer-type lp
    break
 when = 'ps'
  when = 'postscript'        ! PostScriptuse-printer-type ps
    break
  when-other
    display 'Invalid printer type.'
    stop
  end-evaluate
  do list_customers
end-program

In this code, the INPUT command prompts the user to enter the printer type. Because the USE-PRINTER-TYPE command does not accept a variable as an argument, the EVALUATE command is used to test for the six possible values and set the printer type accordingly.

The EVALUATE command is similar to a switch statement in the C language. It compares a variable to multiple constants and carries out the appropriate code.