LearnBrainfuck basics

The machine

By the end of this lesson you can put any number in a cell, using two of the eight commands of brainfuck.

A box with a number

Here are four boxes in a row, all holding 0. Press the buttons until the box numbered 0 holds 5:

A program is a list of presses

Now nobody presses. The seven presses are written out above the boxes as one line, and the marked one comes next. Press Step until the line ends, then drag the slider back and forth to go through it again:

Write a number

Now you write the line. Make cell 0 hold 7, by typing in the box or with the keys under it. Anything that is not one of the eight commands is skipped, so you may add spaces or words. The tape shows where your program ends:

Below zero

The cell holds 0, and the program is a single −. Press Step once and watch the first box:

Check yourself

A free exercise

Make cell 0 hold 250. Typing 250 plus signs would work, but six commands are enough if you remember what the last figure did. Nothing is checked here:

What you can do now

You can put any number from 0 to 255 in a cell with + and −, and read a program one command at a time. These are the commands you know:

The commands of Lesson 1.
CommandWhat it does
+ −Add 1 to the cell under the pointer, or take 1 off.

Type the minus with the ordinary hyphen key. The pages draw it as − so that it is easier to see; both work in every box.

One cell is not much, and the tape has thousands. Lesson 2 moves the pointer along them.