Anonymous user
Find limit of recursion: Difference between revisions
→{{header|VBScript}}: ++ unix shell (bash)
(+Icon+Unicon) |
(→{{header|VBScript}}: ++ unix shell (bash)) |
||
Line 276:
Got to depth 999999
</pre>
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
<lang bash>recurse()
{
# since the example runs slowly, the following
# if-elif avoid unuseful output; the elif was
# added after a first run ended with a segmentation
# fault after printing "10000"
if [[ $(($1 % 5000)) -eq 0 ]]; then
echo $1;
elif [[ $1 -gt 10000 ]]; then
echo $1
fi
recurse $(($1 + 1))
}
recurse 0</lang>
The Bash reference manual says <cite>No limit is placed on the number of recursive calls</cite>, nonetheless a segmentation fault occurs at 13777 (Bash v3.2.19 on 32bit GNU/Linux)
|