A little program simulating recursion graphically.
Controls
- Y Button to call the function
- X Button to finish ( go back ) a function call.
It is only a simulation. So it should not be possible to go back and forth but I had to stop the calls and thought it would be funny to have some control during the process.
Fun(ction) fact!
You can bake recursion directly in to functions themselves!
depth = 0 recursion = function(x) print(depth) flip()--slow things down if(x~=nil)then depth = x end if(depth<=200)then recursion(depth+1) end end recursion() |
@Cabledragon
Nice! I didn`t know about the flip() function yet, that's why I had to use the workaround. Thanks a lot for this hint!
I guess (x~=nil) is the same as (x!=nil) ? :D
Why does the 0 gets printed out in the beginning twice though?
It prints zero twice simply because I set up the order of operations incorrectly.
Also yes, ~= == !=, except that != doesn't exist in standard lua.
All flip() does it draw the contents of the back buffer to the screen. It's used to manually update the screen, but here I use it to slow things down.
oh okay, so the double 0 comes from calling recursion the first time without arguments?
[Please log in to post a comment]