Sub - End Sub

Sub subname ( [parameter-list] )

    [Exit Sub]
End Sub

A Sub procedure is a series of nuBasic statements enclosed by the Sub and End Sub statements.

The Sub procedure performs a task and then returns control to the calling code, but it does not return a value to the calling code.

Corresponding to each parameter in the parameter-list is an argument in the procedure call of the argumentlist.

Calling syntax:
subname [argument-list]

When you call a procedure that accepts one or more parameters you can pass the arguments by position, in the order in which the related parameters appear in the procedure's definition.

Sub print_number ( number% )
    If number% > 10 Then Print "Exit here..." : Exit Sub
    Print "Number:"; number%
End Sub

print_number 20 div 4
print_number 20 * 4

Exit here...

In the following example, the procedure studentInfo(name$,age%) is called with its arguments passed by position and delimited by commas:

' Main Program
studentInfo "John", 20
studentInfo "Mary", 22

' Procedures...
Sub studentInfo(name$, age%)
    Print "Name = " + name$ + " age: " + Str$(age%)
End Sub

Name = John age: 20
Name = Mary age: 22

See also Function