en:subroutine [BASIC 256 - Language Documentation]

# BASIC 256 - Language Documentation

en:subroutine

## Subroutine (Statement)

### Format

subroutine subroutine_name ( variable_list )
statement(s)
end subroutine

subroutine subroutine_name$ ( variable_list )
statement(s)
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 ”calling” program when a 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, 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 definition.

Subroutines should be defined at the bottom of your program, and can not be defined within another Function, Subroutine or control block (If/Then, Do/Until, …)

### Example

    # 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

draws

### See Also

Begin Case / Case / End Case, Call, Continue Do, Continue For, Continue While, Do / Until, End, Exit Do, Exit For, Exit While, For / Next, Function, Global, Goto, Gosub, If Then, Pause, Ref, Rem, Return, Subroutine, While / End While

### History

0.9.9.1 | New To Version

en/subroutine.txt · Last modified: 2014/02/09 14:56 by admin