Enhavo

# GoSub...Return Statement

Calls a subroutine that is indicated by a label inside a Sub or a Function. The statements following the label are executed until the next Return statement. Afterwards, the program continues with the statement that follows the GoSub statement.

### Syntax:

    GoSub label[:]

### Parameters:

label: A line identifier indicating where to continue execution. The scope of a label in that of the routine it belongs to.

The GoSub statement calls a local subroutine indicated by a label from within a subroutine or a function. The name of the label must end with a colon (":").

      Sub/Function foo
          ' statements
          GoSub label
          ' statements
          Exit Sub/Function
      label:
          ' statements
          Return
      End Sub/Function

Se la programo renkontas ordonon Return sen antaŭa GoSub, LibreOffice Basic donas prieraran mesaĝon. Necesas Exit Sub aŭ Exit Function por certigi ke la programo eliras el la Sub aŭ Function antaŭ ol atingi la postan ordonon Return.

La jena ekzemplo montras la uzadon de GoSub kaj Return. Rulante dufoje sekcion de programo, la programo kalkulas la kvadratan radikon de du numeroj tajpitaj de la uzanto.

### Example:

    Sub ExampleGoSub
    Dim iInputa As Single
    Dim iInputb As Single
    Dim iInputc As Single
        iInputa = Int(InputBox("Tajpu la unuan numeron: ","NumberInput"))
        iInputb = Int(InputBox("Tajpu la duan numeron: ","NumberInput"))
        iInputc=iInputa
        GoSub SquareRoot
        Print "La kvadrata radiko de";iInputa;" estas";iInputc
        iInputc=iInputb
        GoSub SquareRoot
        Print "La kvadrata radiko de";iInputb;" estas";iInputc
        Exit Sub
    SquareRoot:
        iInputc=sqr(iInputc)
        Return
    End Sub

Rilataj temoj

GoTo Statement

On...GoSub Statement; On...GoTo Statement