Program Shape and Statements
A LunarBasic program is a sequence of top-level statements. Think of it as a list of actions and declarations the parser reads from top to bottom.
Top-Level Statement Types
- Expression statements
- Assignment statements
- Label statements
- Const declarations
- Dim declarations
- If statements
- While statements
- Do / Loop statements
- For statements
- Repeat / Until statements
- Select / Case statements
- Function declarations
- Goto statements
- Sub declarations
- Type declarations
- Return statements
Type Declarations
User-defined data types are declared at the top level with Type and End Type. Fields are declared inside the block with Field.
Type Player
Field Name As String
Field Score As Integer
End Type
See Types and Objects for the full reference, including New and field access.
Expression Statements
A routine call or a system-function call can stand on its own as a statement.
- Foo()
- obj.method(1)
- Graphics()
System functions also support the bare-call form without parentheses.
Graphics 800, 600
LoadFont "Fonts/ui.ttf", 24
DrawText uiFont, 32, 32, "Hello"
Cls
Flip