Pasted example code.

This commit is contained in:
Bobbi Webber-Manners 2018-05-01 11:49:44 -04:00 committed by GitHub
parent 37943c2d6c
commit d6188ed911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -575,4 +575,27 @@ Then you can run the VM program for your platform. It will load the bytecode fr
## VM Internals
# Code Examples
## Recursive Factorial
This example shows how EightBall can support recursion. I should point out that it is much better to do this kind of thing using iteration, but this is a fun simple example:
pr.dec fact(3); pr.nl
end
sub fact(word val)
pr.msg "fact("; pr.dec val; pr.msg ")"; pr.nl
if val == 0
return 1
else
return val * fact(val-1)
endif
endsub
`fact(3)` calls `fact(2)`, which calls `fact(1)`, then finally `fact(0)`.
See `eightballvm.h` for technical details.
## Prime Number Sieve