Section 11: Branching and Looping160
A common use of a branch is to create a ‘‘loop’’ in a program. For example, the following program calculates and displays the square roots of consecutive whole numbers beginning with the number 1. The calculator continues to compute the square root of the next consecutive whole number until you press R/S to stop program execution (or until the HP-41C overflows).
 
You may wish to clear some of the programs you have recorded in program memory so that you will have room to include the problems in this and following sections. Check CATALOG 1 to see the names fo the programs and delete the ones you don’t wish to save using CLP (clear program). Subsequent problems in the handbook assume that program memory has been cleared of all programs and no key assignments has been made.
Name the program ROOT and assign it to the TAN key location.
Keystrokes Display    
PRGM g GTO · · 
  00 REG 46    
  Sets the HP-41C to program mode and to the end of program memory.
g LBL 
       
   
ALPHA ROOT ALPHA 
  01 LBLTROOT    
  The program name.
  02 0 _    
   
STO 01
  03 STO 01    
  Stores 0 in R01.
g LBL 05
  04 LBL 05    
   
  05 1 _    
   
STO  +  01
  06 STO + 01    
  Adds 1 to the current number in R01.
RCL 01
  07 RCL 01    
  Recalls current number from R01.
XEQ 
       
   
ALPHA PSE ALPHA 
  08 PSE    
  Display current number.
  
  09 SQRT    
  Computes the square root of the number.
XEQ 
       
   
ALPHA PSE ALPHA 
  10 PSE    
  Displays square root of current number.
g GTO 05
  11 GTO 05    
  Transfers execution to the LBL 05 in line 4.
g GTO · · 
  00 REG 43