File: recursion-test-function3.scad

package info (click to toggle)
openscad 2021.01-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,096 kB
  • sloc: cpp: 53,199; sh: 4,384; ansic: 4,382; python: 1,813; yacc: 853; javascript: 762; lex: 417; lisp: 163; xml: 127; makefile: 118
file content (11 lines) | stat: -rw-r--r-- 291 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
//Example without tail-recursion
//https://en.wikibooks.org/w/index.php?title=OpenSCAD_User_Manual/User-Defined_Functions_and_Modules&oldid=3379916#Recursive_functions

function add_up_to(n) = (
    n==0 ? 0 : n + add_up_to(n-1)
    );

echo(sum10=add_up_to(10));
echo(sum=add_up_to(-1));