Internal Subprogram ☆
A subprogram describes a definite procedure as an object.
An internal subprogram is a subprogram written within a program unit, begins with a SUB line and ends with a END-SUB line.
A SUB line describes its name and parameters. The parameters are written separated by commas and enclosed in parentheses if any.
The rule for naming a subprogram is the same as that for a numeric variable.
Use a CALL statement to execute a subprogram. To execute a subprogram that has parameters, write the arguments enclosed in parentheses as in function reference.
100 OPTION ANGLE DEGREES 110 SUB circle(a,b,r) 120 FOR t=0 TO 360 130 PLOT LINES: a+r*COS(t),b+r*SIN(t); 140 NEXT t 150 PLOT LINES 160 END SUB 170 SET WINDOW -4,4,-4,4 180 CALL circle(1,-1,2) 190 CALL circle(-1,2,1) 200 END
All variables except parameters are common with the program unit.
When the control comes to the SUB-line, it jumps to the next line to the END-SUB line.
If a CALL statement is executed , the control jumps to the SUB-line, and if it reaches the END-SUB-line, it returns to the next line to the CALL-line.