Show Menu

PureBasic Cheat Sheet by

This Cheat Sheet only contains the basic PureBasic keywords. It does not contain any library calls. It is meant as a guide to get you writing PB code quickly. Refer to the full documentation for information on how to use the libraries. Get your own free copy at

Flow Control

Break [Level]
Will break out of an If/Then, While/Wend or Repeat­/Until code block. If the optional Level is specified, will break out of that number of nested flow blocks.
Will skip directly to the start of the code block, skipping any statements between the Continue and the end of the code block
For <va­ria­ble> = <ex­pre­ssi­on1> To <ex­pre­ssi­on2> [Step constant]
Defines a for loop, counting variable from expres­sion1 to expres­sion2, optionally increm­enting by Step. The "­To" value can be changed inside the loop.
Next [variable]
Increments variable and loops through the For loop again. Variable is optional and only included for readab­ility
ForEach List() | Map()
Loops through all of the elements in the specified list or map
Next [List() | Map()]
Increments the ForEach loop. List() or Map() is optional and only included for readab­ility
Gosub label
Send program execution to the code at label, and then the program will resume on the next time
Returns to the code following the Gosub call.
If Goto is used inside of a subrou­tine, you must use FakeReturn before the Goto
Goto label
Send program execution to the code at label
If <ex­pre­ssi­on>
Starts an If block. The code inside the block will be executed if <ex­pre­ssi­on> evaluates to #True.
ElseIf <ex­pre­ssi­on>
An additional If inside an If block, evaluated if the previous If returned #False.
The code following Else will be executed if all previous If and ElseIf expres­sions evaluated to #False
Ends an If block
Select <ex­pre­ssi­on>
Start a Select block and use the value of <ex­pre­ssi­on> for the compar­isons
Case <co­nst­ant­>[, ...]
Compares the value of the Select expression to <co­nst­ant> and executes the following code block if it evaluates to #True.
A code block to run if none of the previous Case statements evaluated to #True
Ends a Select block
Begins a Repeat block. Unlike If or While, a Repeat block is always executed at least once.
Until <ex­pre­ssi­on>
Ends a Repeat block. If <ex­pre­ssi­on> evaluates to #False, will run the Repeat block again until <ex­pre­ssi­on> evaluates to #True
Ends a Repeat code block and turns it into an infinite loop. Will run forever until the app is killed or a Break statement is encoun­tered
While <ex­pre­ssi­on>
Begins a While code block. Will repeat the block until <ex­pre­ssi­on> evaluates to #False.
Ends a While code block
Only use a single = in expres­sions, e.g. "If i=0". Do not use Then, which is not a keyword.

You can use ranges in Case statem­ents, e.g. "Case 1 To 8"

Compiler Directives

CompilerIf <Co­nstant Expres­sio­n>
If <Co­nstant Expres­sio­n> evaluates to True, the code block will be compiled, else it will be skipped during compil­ation
Compil­erE­lseIf <Co­nstant Expres­sio­n>
Compil­erElse <Co­nstant Expres­sio­n>
Ends the CompilerIf code block
Compil­erS­elect <Nu­meric Consta­nt>
Starts the Compil­erS­elect code block.
Compil­erCase <Nu­meric Consta­nt>
If <Nu­meric Consta­nt> is True, the code block will be compiled, else skipped during compil­ation
Ends the Compil­erS­elect code block
Compil­erError <String Consta­nt>
Generates a compiler error and displays <String Consta­nt>
Compil­erW­arning <String Consta­nt>
Generates a compiler warning and displays <String COnsta­nt>
Enables Explicit mode. When enabled, all the variables which are not explicitly declared with Define , Global , Protected or Static are not accepted and the compiler will raise an error.
Disables Explicit mode
Enables the inline assembler
Disables the inline assembler

Compiler Functions

Returns the size of the variable type or complex structure
Offset­Of(­Str­uct­ure­\Field | Interf­ace­\Fu­nct­ion())
Returns the address offset of a Structure field or the address offset of an Interface function
Returns the type of a variable or structure field.
Subsys­tem­(<C­onstant String Expres­sio­n>)
Determine if a subsystem is in use for the program being compiled
Define­d(Name, Type)
Checks if object Name has been defined or not.
Initia­liz­eSt­ruc­tur­e(*­Poi­nter, Structure)
Initialize the specified structured memory area. It initia­lizes structure members of type Array, List and Map
CopySt­ruc­ture(Source, Destin­ation, Structure)
Copies structured memory from Source to Destin­ation
ClearS­tru­ctu­re(­*Po­inter, Structure)
Clears a structured memory area
ResetS­tru­ctu­re(­*Po­inter, Structure)
Clears a structured memory area and initia­lizes it for use
Bool(<­boolean expression >)
Can evaluate a boolean expression outside of a flow control block. Will return #True or #False

Compiler Object Types

These are the types that are returned from the compiler function TypeOf

Compiler Defined Types

These are the types that can be specified in the compiler function Defined


At the start of a number, indicates that this is a binary number
At the start of a number, indicates that this is a hexade­cimal number

Compiler Reserved Constants

Determines on which OS the compiler is currently running. Can be one of the following:
The compiler is running on Windows
The compiler is running on Linux
The compiler is running on macOS
Determines the processor type for which the program is created. Can be one of the following:
Intel x86 (IA -32 or x86 -32)
Intel x64 (x64, AMD64 or Intel64)
Arm 32-bit
Arm 64-bit, Apple Silicon
Determines which kind of compiler is currently used. Can be one of the following:
The compiler generating Assembler is being used
The compiler generating C is being used
Determines executable format. Can be one of the following:
A regular executable
A console execut­able. Only matters on Windows
A shared DLL in Windows. A dynlib in macOS, a shared object in Linux
The current date at compile time, in PureBasic date format
The full path and name of the file being compiled
The full path of the file being compiled
The filename (without path) being compiled
The current line number being compiled
The current Procedure being compiled, if applicable
The current module being compiled, if applicable
The compiler version, in integer format
The full path of the PureBasic directory
Set to 1 if debugger enabled, 0 otherwise
Set to 1 if the executable was compiled in thread safe mode, 0 otherwise
Set to 1 if the executable was compiled in Unicode, 0 otherwise
Set to 1 if the executable was compiled with OnError line numbering support, 0 otherwise
Set to 1 if the executable was compiled with inline assembly, 0 otherwise
Set to 1 if the executable was compiled with Enable­Exp­licit, 0 otherwise
Set to 1 if the file being compiled is the main file, 0 otherwise
Set to 1 if the file being compiled has been included by another file, 0 otherwise
Set to 1 if the compiler generates 32-bit code, 0 otherwise
Set to 1 if the compiler generates 64-bit code, 0 otherwise
Set to 1 if the compiler generates optimizer code, 0 otherwise
All constants start with #.

These constants are useful for the Compiler Directives (Compi­lerIf, Compil­erS­elect).

Data Blocks

Starts a Data section, a predefined block of inform­ation
Ends the Data section
Defines data
Restore label
Will set the start of Read to label
Read[.T­ype] <va­ria­ble>
Read the next available data

Debugging Functions

Invokes the debugger and freezes the program
Debug <ex­pre­ssi­on>[, DebugL­evel]
Display the Debug output window and show the result of Expression in it. The ’Debug­Level’ is the priority level of the debug message.
DebugLevel <co­nstant expres­sio­n>
Set the current Debug level
Disable debugger checks in the subsequent code
Enable debugger checks in the subsequent code


Define.<t­ype> [<v­ari­abl­e> [= <ex­pre­ssi­on>]][, ...]
Defines one or more variables of Type type and optionally initia­lizes them
Define <va­riable >.<type > [= <ex­pre­ssion >]][, ...]
Alternate form of Define
Dim name.<­typ­e>(­<ex­pre­ssi­on>, ...)
Creates new arrays
ReDim name.<­typ­e>(­<ex­pre­ssi­on>, ...)
Resize an existing array. Will only affect the last dimension of a multid­ime­nsional array
Enumer­ation [name] [<c­onstant > [Step <co­nstant >]]
Creates a new enumer­ation named name
Enumer­ati­onB­inary [name] [<c­onstant >]
Creates a new binary enumer­ation named name. Binary enumer­ations can be used for flags.
Ends the Enumer­ation definition
Global­[.<­typ­e>] <va­ria­ble­[.<­typ­e>]> [= <ex­pre­ssi­on>][, ...]
Defines the scope of the variables to be global rather than local
NewList name.<type >()
Creates a new, dynamic List of Type <ty­pe>.
NewMap name.<­typ­e>(­[Sl­ots])
Create a new Map (Hash, Dictio­nary). The keys are always of type String, the values will be of Type <ty­pe>. If Slots is not specified, will be dynami­cally allocated as needed.
Protec­ted­[.<­typ­e>] <va­ria­ble­[.<­typ­e>]> [= <ex­pre­ssi­on>][, ...]
Allows a variable to be accessed only in a Procedure even if the same variable has been declared as Global in the main program
Shared <va­ria­ble­>[, ...]
Allows a variable, an array, a list or a map to be accessed within a procedure
Static­[.<­typ­e>] <va­ria­ble­[.<­typ­e>]> [= <co­nstant expres­sio­n>][, ...]
Allows creating a local persistent variable in a Procedure even if the same variable has been declared as Global in the main program
Structure <na­me>
Begins a Structure definition
Structure <na­me> Extends <st­ruc­t_n­ame>
Begins a Structure definition that add to an existing Structure
Structure <na­me> Align <n>
Begins a Structure definition where every element is aligned to an <n>­-byte boundary. Align can be used with Extends also.
Ends a Structure definition block
Begins a Struct­ure­Union definition block
Ends a Struct­ure­Union definition block
Thread­ed[.<t­ype­>] <va­ria­ble­[.<­typ­e>]> [= <co­nstant expres­sio­n>][, ...]
Allows creating a thread persistent variable
Starting a variable with # makes it a constant, e.g. #Pi=3.14


Import "­Fil­ena­me"
Allows declaring external functions and variables from a library or object
Declares an external variable
Functi­onN­ame.<t­ype­>(<­par­ame­ter­>[ = Defaul­tVa­lue][, ...]
Declares an external function
Ends the Import declar­ations
Includ­eFile "­Fil­ena­me"
Includes the specified source code file at the current position
XInclu­deFile "­Fil­ena­me"
The same as Includ­eFile, but with protec­tions to avoid including the same file twice.
Includ­eBinary "­fil­ena­me"
Will include the file at the current position. Should be done in a Data block
Includ­ePath "­pat­h"
Will set the default path for all subsequent Include files
Macro <na­me> [(Para­meter [, ...])]
Starts a Macro block. A placeh­older for code that can be directly inserted into the source code wherever the Macro is called
Ends the Macro block
Undefi­neMacro <name >
Undefines Macro <na­me>
The number of times the Macro has been called­/ex­panded
Declar­eModule <name >
Defines the public interface to Module <na­me>
Ends the public module declar­ation
Module <na­me>
Starts the implem­ent­ation of the Module
Ends the Module code block
USeModule <na­me>
Can use any module that had a previous public declar­ation
UnUseM­odule <na­me>
Removes the previously used module
End [ExitCode]
Ends the program correctly. If ExitCode is specified, the program will return it as the exit code to the OS.
Swap <ex­pre­ssi­on1­>, <ex­pre­ssi­on2>
Does an optimized swap of the expres­sions


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Metasploit 4.5.0-dev.15713 Cheat Sheet
          LSI Logic MegaRAID Cheat Sheet
          Windows Terminal Cheat Sheet

          More Cheat Sheets by DNSGeek

          Vision BASIC Cheat Sheet