Documentation

BrainF++ documentation

Complete guide to programming in BrainF++ and using the contest platform.

Quick reference
Essential BrainF++ commands
>
Move pointer right
>>
<
Move pointer left
<<
+
Increment cell
++++
-
Decrement cell
----
.
Output character
.
,
Input character
,
[
Start loop
[
]
End loop
]
;
Return value from function
;
{
Start function declaration
{mn
}
End function declaration
}
(
Start function call
(ab
)
End function call
)
Functions
BrainF++ function system

Function declaration

Functions are declared with curly braces. The syntax is {ab code here} where the two-letter function name immediately follows the opening brace, followed by the function code, then the closing brace.

{ab+++.}// Function named "ab"

Main function

Execution always begins in the main function {mn code here}. Code outside of any function is ignored and does not execute.

{mn+++.}// Main function - this runs

Return values

Use the semicolon ; command to return a value from a function. The current cell value is returned and replaces the cell value at the call site.

{ab++++++;}// Returns 6

Function calls

To call a function, use parentheses with the two-letter function name: (ab). The current cell value is passed as input, and the return value replaces the current cell.

{ab+++;}
{mn++(ab).}// Calls function "ab"

Global cells

Global cells are cells which are accessible to the left of the starting cell. They are static across all function calls.

{ab<-[>+;]}// Returns 1 if the global cell is >0, 0 otherwise
{ab<-[>+;]}// Decrements global cell, returns 1 if it is positive
{mn<.>+[>(ab)]}// Moves right the inputted number of times
Common patterns
Useful code snippets and techniques

Go to next empty cell

[>]// Goes to the next empty cell

Clear current cell

[-]// Sets current cell to 0

Transfer cell to next cell

[->+<]// Transfers a cell to the next cell (or adds it to the next cell)

Duplicate cell to next cell

[->+>+<<] >>[<<+>>-]// Duplicates a cell to the next cell

Conditional function call

[(AB);](ab)// Does function AB if the current cell is nonzero but function ab if current cell is zero

Conditional return

[;]// Returns the value of a function if it is not 0