Syntax basics

Case

Keywords, names, types and constants are case-insensitive. Count, count and COUNT are one variable. String contents are case-sensitive: "a" = "A" is false.

Statements

A new line ends a statement. A statement continues onto the next line when the line ends with something that can't end a statement: an operator, a comma, or an open ( or [.

OpenConsole()
total = 1 +
        2 +
        3
PrintN(Str(total))

Output:

6

: puts several statements on one line:

OpenConsole()
a = 1 : b = 2 : PrintN(Str(a + b))

Output:

3

Comments

Form Meaning
; text comment to the end of the line (PureBasic)
// text comment to the end of the line (C)
/* text */ block comment. Doesn't nest

; is a comment only outside brackets. Inside ( ), [ ] or { } it separates statements, which is what lets C code like for (i = 0; i < n; i++) work. A ; at the end of a C-style line just starts an empty comment, so int x = 0; is fine.

Watch out for a = 1; b = 2 written at the top level: everything after the ; is a comment there. Inside { } blocks, use // for comments.

Names

Form Example Is
name count a variable, procedure, array, …
name$ title$ a string variable. title$ and title are two different variables
*name *buffer a pointer variable (the * is part of the name)
#name #Width a constant

A name starts with a letter or _ and continues with letters, digits and _.

Words that are keywords only in context

Array, List, Map and Align are keywords only where the grammar expects them, as in PureBasic. List items.s() in a structure or parameter list declares a list. A plain list used anywhere else is an ordinary name. So is align in a field or variable.

OpenConsole()
list.i = 3
align.i = 8
map$ = "world"
PrintN(Str(list * align) + " " + map$)

Output:

24 world

The other C-style and x keywords (var, switch, int, …) work the same way. PureBasic's own keywords (If, For, Procedure, …) are always reserved; to use one as a name, write it in backquotes: `next`.

Number literals

Form Example Value
decimal 1_000_000 1000000. _ is ignored
hexadecimal $FF or 0xFF 255
binary %1010 or 0b1010 10
character 'A' 65, the character's UTF-16 code
floating point 3.5, 1e-3, 2.5f a double, unless it ends in f (float)

String literals

OpenConsole()
PrintN("C:\temp\file.txt")
PrintN("Say " + Chr(34) + "hi" + Chr(34))

Output:

C:\temp\file.txt
Say "hi"

A plain string literal contains exactly the characters between the quotes. A backslash has no special meaning, which suits Windows paths.

🔜 ~"…" strings will process escapes such as \n, \t and \".

Blocks

Every block has two forms: a closing keyword (PureBasic) or braces (C). Choose either.

OpenConsole()
x = 5
If x > 3
  PrintN("big")
EndIf
if x > 3 {
  PrintN("still big")
}

Output:

big
still big

There is no braceless one-line form like C's if (x) y = 1. For a short If, write If x : y = 1 : EndIf or if x { y = 1 }.