Last active
December 25, 2015 02:58
-
-
Save preprocessor/6905991 to your computer and use it in GitHub Desktop.
Tail recursion in lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countdwn(n) | |
while n>0 do | |
print(n) | |
countdwn(n-1) | |
else | |
print("0") | |
end | |
end | |
--[[ | |
Usage: countdwn(natural number) | |
> countdwn(10) | |
10 | |
9 | |
8 | |
7 | |
6 | |
5 | |
4 | |
3 | |
2 | |
1 | |
0 | |
> | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment