BrainFu / Tutorial / Page 1
Learn Programming in 30 minutes, Here and Now
Page 1 of 3
Published 2024/04/29
Hello and welcome to this computer programming tutorial.
This tutorial is an introduction to computer programming for complete beginners. It uses the programming language BrainFu to explain the most essential computer programming concepts.
The language BrainFu is an excellent first programming language to learn, due to its overwhelming simplicity. With only eight commands to learn, you'll be able to get started quickly and easily. Other computer languages usually require learning hundreds of commands. Learning eight simple commands should be fast and easy. In less than 30 minutes, you will learn the entire programming language BrainFu.
The Interpreter's Interface
Before you start writing programs in the language BrainFu, you need to familiarize yourself with the BrainFu interpreter. The online interpreter is available on this page. To get started, click on the “ ” button to execute the example programs, one by one.
You'll notice that some example programs end immediately, while others take a long time to end, or don't end at all. Don't worry - you can terminate any program using the interpreter's “
” button.The Eight Commands of the Language BrainFu
The language BrainFu consists of only eight simple commands. It is a good idea to have a quick glance at all of them. Here they are:
Name | Symbol | Description |
---|---|---|
increment | + | increase the value by one |
decrement | - | decrease the value by one |
output | . | output one byte |
input | , | input one byte |
move left | < | move one cell to the left |
move right | > | move one cell to the right |
skip | [ | if the cell value is zero, then skip all commands before the matching bracket |
repeat | ] | if the cell value is nonzero, then go back to the first command after the matching bracket |
In the table, each command has a name and a symbol. The symbol for each command is just one character.
The Debugger's Interface
Now you need to familiarize yourself with the debugger. The debugger allows you to step through a program one instruction at a time, so that you can see each command being executed.
To get started, select the first example program, “
”. Then, click the “ ” button. The debugger's interface will be displayed.Click the “
” button to start the “Hello World!” program. The program won't execute any commands yet. The program won't execute any commands yet. The "Watch" box displays the contents of the first 40 memory cells. All the memory cells will be reset to a value of zero, and the first cell, numbered "0", will be highlighted in green color.As you click the “
” button many times, the values of the memory cells will increase. The debugger executes one command every time you click the “Step by 1 instruction” button. You can observe the execution of commands in the instruction stream above the “Step” buttons. An “instruction” is just another name for a command.Try clicking the “
” button at least 40 times, and observe the changes.The program will output the text “Hello World!” near the end of the execution. The entire execution is 390 instructions long. If you like, you can try out the other “
” buttons to step faster through the program. You can also use other buttons to restart or terminate the program.What do the Commands do?
If you click the “
” button slowly, you'll be able to observe that most instructions do exactly what the table of commands says, as described earlier in this article.The instruction + increases a memory cell by one; the instruction > moves one cell to the right, etc.
In the next chapter, you'll learn how to write your own programs using the eight commands of the BrainFu language.