Section 11
Branching and Looping
Branching and Looping
Earlier in this handbook you learned how you can use GTO · and a program line number of ALPHA label to position the calclator to a particular place in program memory. In addition, you saw how GTO · · positioned the calculator ot the end of program memory to prepare the calculator for a new program. You can also use GTO (go to label) in your programs followed by an ALPHA or numeric label to transfer execution to any part of a program you desire.
A GTO instruction used in this way is known as an unconditional branch. It always branches execution to the specified label. (Later, you will see how an condition instruction can be used in conjunction with a GTO to create a conditional branch—a branch that depends on the outcome of a test.)
Here is what a GTO branch would do if a program in the HP-41C looked like this:
  Execution branches to the next
GTO 01  
  LBL 01 in the program.        
    LBL 01  
When the program encounters the GTO 01 instruction, execution immediately halts and the calculator searches sequentially downward through the program for the first occurrence of a LBL 01. If the calclulator does not find a LBL 01 before reaching the end of the program (an END instruction), the calculator starts searching from the top of the program until it finds the LBL 01. If the label does not exist, the HP-41C will display NONEXISTENT and the calculator will be positioned to the same line it was prior to beginning the search. Press    to clear the error.