Hello, World! in Befunge
First part of the example pushes the required values on the stack.
25* puts 10 on the stack (ASCII-code of new line), then
" toggles string mode, in which each character of the program pushes its ASCII-code on the stack, and finally second
" toggles string mode off.
Second part of the example is a loop which prints all values in the stack, starting from the topmost ones.
> makes the instruction pointer move right (after the end of iteration).
: duplicates the topmost element of the stack (i.e., the current character); due to usage of the bridge
# this command is executed only when the instruction pointer moves to the right.
, prints the topmost element of the stack; due to the bridge it is executed only when the IP moves to the left.
_ allows the IP to pass to
@ if the topmost element of the stack is 0 (or the stack is empty) and mirrors it back to moving left otherwise. The order of events within one iteration is:
- duplicate the topmost element of the stack.
- check, whether it’s equal to 0; if it is, break the loop. During this check the topmost element is always deleted.
- print the topmost element of the stack.
25*"!dlroW ,olleH" >:#,_@