User Tools

Site Tools


el:subroutine

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

el:subroutine [2016/01/01 22:40]
el:subroutine [2020/02/28 10:46] (current)
Line 1: Line 1:
 +===== Subroutine =====
  
 +==== Format ====
 +**subroutine** subroutinename ( //variable list// )\\
 +//statements//\\
 +**end subroutine**
 +
 +**subroutine** subroutinename$ ( //variable list// )\\
 +//statements//\\
 +**end subroutine**
 +
 +==== Description ====
 +Create a subroutine (or subprogram) that will receive zero or more values and process those values.  A subroutine does not return a value back to the user, it just does what you want it to do.  Execution of a subroutine will terminate and control will be returned to the "[[call|call]]ing" program when a [[Return|Return]] statement is executed or by allowing the //End Subroutine// statement to be reached.  All variables used within the subroutine, that have not been previously declared as [[global|Global]], will be local to the subroutine and will not change the values in the calling code.
 +
 +Subroutine variables may a list of zero or more, comma separated, numeric or string variables.  Arrays and variables may be passed by reference using the [[Ref|Ref]] definition.
 +
 +Subroutines should be defined at the bottom of your program, and can not be defined within another [[function|Function]], [[Subroutine|Subroutine]] or control block ([[ifthen|If/Then]], [[dountil|Do/Until]], ...)
 +
 +==== Example ====
 +
 +<code>
 +# 100 random circles
 +clg
 +for x = 1 to 100
 +   call draw()
 +next x
 +end
 +
 +function rnd(n)
 +   rnd = int(rand*n)
 +end function
 +
 +subroutine draw()
 +   color rnd(256),rnd(256),rnd(256)
 +   circle rnd(graphwidth), rnd(graphheight), rnd(graphwidth/10)
 +end subroutine
 +</code>
 +draws\\
 +{{:en:subroutine_circle.png|Circles}}
 +==== See Also ====
 +{{page>en:start#Program Control&noheader}}
 +
 +==== New To Version ==== 
 +0.9.9.1
el/subroutine.txt ยท Last modified: 2020/02/28 10:46 (external edit)