LearnBrainfuck basics

Moving and copying

By the end of this lesson you can move a value to another cell, add two values, and copy one.

Pour it over

A value that you read or built sits in one cell, and sooner or later you need it somewhere else. Cell 0 holds 5, and the program is a loop of six commands. Press Play, or drag the slider through the steps, and watch both cells:

Two cells further

The box holds the loop of the first figure. Change it so that the value of cell 0 lands in cell 2 instead of cell 1. It must work for any value, so it is tried with 7 and with 3:

Keep the original

Cell 0 holds 4, and the program has two loops. Press Play, or Step through it, and watch all three cells:

Adding

Cell 0 holds 3 and cell 1 holds 4. Write a program that leaves their sum in cell 1. It must work for other numbers too, so it is also tried with 10 and 1:

Check yourself

A free exercise

Cell 0 holds 6. Leave twice that, 12, in cell 1. Then try three times. Nothing is checked here:

What you can do now

You can move a value with [−>+<], add by moving into a cell that is not empty, and copy with a scratch cell. No new command came in this lesson: all three are the loop of Lesson 4. Patterns has a page for each, with variations: move, copy and add and subtract.

A loop that runs once or not at all is a decision. Lesson 8 uses it that way.