|
|
|
< conditional loops |
User Functions |
recursion > |
|
|
Loops are not the only way to set up repeatable code. Parts of a program can be stored in user-defined functions, and run whenever you like by calling the function. For example: // three right-angled triangles tri: {^<^*2} To create a function, type the name followed by a colon : and then the code the function must run. Here the function 'tri' contains code to draw a triangle. To call a function, type its name followed by brackets. The brackets can contain a list of parameters to pass to the function, or they can be empty, as here. A function can also return a value, using the return keyword. // passing parameters and returning a value setsize: return #_1 ** #_2 here we pass two parameters to the setsize function. The function can access these as local variables. The value returned by the function is used to set the length of the second line. The ** operator means 'raised to the power of'
|
|
< conditional loops |
recursion > |