Keyword End - leonard-thieu/monkey GitHub Wiki

Declares the end of a class, function, method or similar block-style definition, or of certain loop or conditional blocks.

Syntax

  Block keyword   End [ Block keyword ]

Description

The End keyword closes off a class, function, method or similar block (eg. interfaces, future additions), but may also be used in place of block-specific keywords which close certain loops or conditional blocks (ie. those that don't need to perform testing at the end of the block).

End may also be combined with a space followed by the block opening keyword. For example, a Class block may be closed by End or End Class according to individual preference.

Some examples are listed below.

Class-block closing options

Class
    ' Contents...
End
Class
    ' Contents...
End Class

Function-block closing options

Function
    ' Contents...
End
Function
    ' Contents...
End Function

If-block closing options

If
    ' Contents...
Endif
If
    ' Contents...
End
If
    ' Contents...
End If

Select-block closing options

Select
    ' Contents...
End
Select
    ' Contents...
End Select

For-loop closing options

For
    ' Contents...
Next
For
    ' Contents...
End
For
    ' Contents...
End For

While-block closing options

While
    ' Contents...
Wend
While
    ' Contents...
End
While
    ' Contents...
End While

See also

Examples

Classes, functions, etc:

' CLASS BLOCKS:

    Class Animal
        ' Code
    End

    Class Animal
        ' Code
    End Class

' FUNCTION BLOCKS:

    Function Walk ()
        ' Code
    End

    Function Walk ()
        ' Code
    End Function

Loop/conditional blocks:

' IF BLOCKS:

    If a = b
        ' Code
    Endif

    If a = b
        ' Code
    End If

    If a = b
        ' Code
    End

' FOR BLOCKS:

    For a = 1 To 10
        ' Code
    Next

    For a = 1 To 10
        ' Code
    End For

    For a = 1 To 10
        ' Code
    End

' WHILE BLOCKS:

    While a < b
        ' Code
    Wend

    While a < b
        ' Code
    End While

    While a < b
        ' Code
    End