[OpenSCAD] for loop in a function

Torsten Paul Torsten.Paul at gmx.de
Tue Apr 10 20:26:33 EDT 2018


And just for fun, a non-recursive version using the c-style
for loop (needs to be enabled as experimental feature in
the dev snapshots)...

function addVector(aVector, start, end) = [ for (i = end, a = aVector[i];i >= start;i = i - 1, a = a + aVector[i]) a ][end - start];

I guess it's more a puzzle kind of solution as I think the
recursive one is more obvious and due to the tail-recursion
elimination maybe even faster than the one above :).

ciao,
   Torsten.



More information about the Discuss mailing list