
Example
The following example creates the list of marks used in the previous
example. If a non-numeric value is entered, the program prompts with an
error message. The program performs the following:
® It sets up a loop to collect 20 values.
® It prompts for an input value.
® It tests the input to check if it is a number.
® If the generates an error, the error is trapped, and an error message is
displayed to prompt for a numeric value.
«
@ Set numeric mode so that error trap works
SF{-3) ;
@ Create an empty list
{}►marks ;
@ Set up a loop for 20 entries.
WHILE SIZE(MARKS)<20 REPEAT
@ Start error-checking routine.
IFERR INPUT("Enter a number","") N
@ Attempt to convert the entry to a number.
@ This generates an error if non-numeric
« OBJ^(N)+l-l -y N
® If no error, append the entry to the list.
« MARKS+N ► MARKS
THEN
©This appears if entry is non-numeric.
MSGBOX("INVALID ENTRY, TRY AGAIN")
END ;
END
Page 10-16
Introduction to programming
Comentários a estes Manuais