[OpenSCAD] for loop in a function

NateTG nate-openscadforum at pedantic.org
Tue Apr 10 20:32:34 EDT 2018


> function sumv(v,i,s=0) = (i==s ? v[i] : v[i] + sumv(v,i-1,s));Depending on
the application, you might want something like:
function sumv(list,start,end) =  start>=end?     0  :    
list[start]+sumv(list,start+1,end);
so that it terminates on bad input.  Of course that version doesn't take
advantage of the overloading on + the way that the one above does.



--
Sent from: http://forum.openscad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180410/a7829024/attachment.html>


More information about the Discuss mailing list