Skip to content

Language

Narta Xaymar Dirks edited this page Oct 27, 2026 · 9 revisions

Language

The syntax and keywords of the language, which is the same in BlitzBasic, Blitz3D and BlitzPlus. Commands such as Print, Rect or CreateCube are in the Command-Index, this page is about what the compiler understands by itself. Keywords and names are not case sensitive, and ; starts a comment that lasts to the end of the line.

Variables and types

A variable has one of three types, which a suffix on its name says: % is an integer (also the default), # a float, $ a string. Variables you assign to are created on first use. Local makes a variable that only exists in its function, Global makes one that every function can see, and Const makes a name for a value that cannot change.

Const LIMIT = 3
Global total% = 0
For i = 1 To LIMIT
	total = total + i
Next
half# = total / 2.0
name$ = "sum"
Print name$ + " " + total + " " + half#
sum 6 3.0

Int, Float and Str convert between the types (Int rounds to the nearest whole number), and Handle and Object convert between an object and a number that stands for it.

Print Int(3.7)
Print Float(2) / 4
Print Str(12) + "!"
4
0.5
12!

Operators

Operators Meaning
+ - * / ^ Arithmetic. Dividing two integers gives an integer, so use a float to get a fraction.
Mod Remainder of a division.
Shl Shr Sar Shift bits left, right, and right keeping the sign.
And Or Xor Not Bitwise and logical operators.
= <> < > <= >= Comparison. They give 1 for true and 0 for false.
Abs() Sgn() Pi Absolute value, sign (-1, 0 or 1) and the number 3.14159.
Print 7 Mod 4
Print 1 Shl 4
Print -8 Sar 1
Print 5 Xor 1
Print Abs(-3)
Print Sgn(-2)
3
16
-4
4
3
-1

Control flow

x = 2
If x = 1
	Print "one"
ElseIf x = 2
	Print "two"
Else
	Print "many"
EndIf

Select x
	Case 1 : Print "case one"
	Case 2, 3 : Print "case two or three"
	Default : Print "default"
End Select

For i = 10 To 1 Step -4
	Print i
Next

While x < 4
	x = x + 1
Wend

Repeat
	x = x - 1
Until x <= 2
Print x
two
case two or three
10
6
2
2

Exit leaves the closest loop, Repeat ... Forever loops until Exit, Goto jumps to a .label, and Gosub calls the code at a label that ends with Return.

Functions

Function Double(n)
	Return n * 2
End Function

Function Greet$(name$, loud = 0)
	If loud Then Return Upper$(name$) + "!"
	Return name$
End Function

Print Double(21)
Print Greet$("hi")
Print Greet$("hi", 1)
42
hi
HI!

A suffix after the function name says what type it returns, and a parameter with = value is optional.

Arrays

Dim makes an array whose indices go from 0 up to the number you give, so Dim a(3) has four elements.

Dim a(3)
a(2) = 5
Print a(2)
Dim grid(2, 2)
grid(1, 2) = 9
Print grid(1, 2)
5
9

Types

A Type describes a record with fields. New creates one, Delete removes it, and \ reads a field. Every type keeps a list of its objects, which First, Last, Before, After and For ... Each walk through, and Insert moves an object inside that list.

Type Point
	Field x, y
End Type

For i = 1 To 3
	p.Point = New Point
	p\x = i
Next

For p.Point = Each Point
	Print p\x
Next

Delete First Point
l.Point = Last Point
Print l\x
1
2
3
3

Data

Data holds values in the program, Read takes the next one, and Restore goes back to a label.

Restore numbers
Read a
Read b
Print a + b
.numbers
Data 3, 4
7

Restore also works inside a function: it goes to a label of the main program, which is where Data is.

A value can also be a calculation of constants, such as 40 - 170, 2 * 3.5 or "Blitz" + "LLVM". It is worked out while compiling, so it can not use variables.

Const Offset = 100
Restore values
Read a
Read b
Read c$
Print a + b
Print c
.values
Data 40 - 170, Offset * 2, "Blitz" + "LLVM"
70
BlitzLLVM

Other keywords

Include "file.bb" puts another source file in this place, True and False are 1 and 0, Null is the empty object, and End stops the program.

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally