Using the YES/NO Test
The Y/N test gives you an easy way to let the user control the program by answering yes or not to a question. Unlike the tests discussed previously in this chapter, the Y/N test does not compare any numeric values in the program.
The YES/NO Test
When you press [ TESTS ], you can the Y/N test into your program.{ Y/N } - Defines the [ F1 ] key as YES and the [ F2 ] key as NO and halts the program. This lets the user of your program responde to an alpha message you have placed in the display.
If you press { NO } in response to the Y/N test, the first instruction following the test is skipped. If you press { YES } in response to the Y/N test, execution continues in normal sequential order.
Although you could create a yes/no menu using the DFN instruction, the Y/N test has the following advantages whenever you want a program to pose a yes/no question.
- You do not have to include { YES } and { NO } function key definitions.
- You do not have to include a HLT instruction in the program.
- You do not have to clear any function key definitions. (The calculator clears the definitions automatically.)
Example
The following program creates a loop that calculates the square roots of a sequence of numbers beginning with 1. The program uses a Y/N test to ask if you want to sum each result to data register B.PC = | Program Mnemonics | Comments |
---|---|---|
0000 | 0 STO A STO B | Initializes A and B |
0005 | LBL AA | Begins loop |
0008 | INC A | Increments count |
0010 | RCL A | Gets current count |
0012 | SQR | Calculates square root |
0013 | PAU | Displays square root |
0014 | `SUM TO B?` | Creates message |
0023 | Y/N | YES/NO test |
0024 | ST+ B | { YES } - Sum to B |
0026 | GTL AA | Repeats loop |
Running the Example
Run the program and sum the values of the first and third square roots.Procedure | Press | Display |
---|---|---|
Start the program | [ RUN ] { PGM } | |
Sum 1st number | { YES } | |
Don't sum 2nd number | { NO } | |
Sum 3rd number | { YES } | |
Check the sum | [ RCL ] B | |
Clear function keys | [ 2nd ] [ F:CLR ] |
☚ Back