Is recursion or iteration faster in Snap?

Is recursion or iteration faster in Snap? By recursion, I mean blocks that iterate over something by calling itself, and by iteration, I mean blocks that iterate over something using for/repeat/while loops.

Hmm, I think I just answered this in another thread.

But a different kind of answer is that the for/repeat/while loops are primitives, and anything that's done as a primitive will be faster than the same thing as interpreted Snap! code. That has more of an effect than recursion vs. iteration per se.

P.S. Thank you for being serious on the forum. I look forward to reading your posts.

1 Like

So using primitives instead of custom blocks will result in programs running faster? Which is why you added the for loop (, IIRC) as a primitive?

No, mainly wanted the former tools library blocks to be always available, so we wouldn't have to tell students to import them first for our programming assignments. That's the reason why we made them primitives. In doing so we were able to tweak them a little bit to make them faster.

I see. Thank you very much.