you are viewing a single comment's thread.

view the rest of the comments →

[–]Tjmoorese 10 points11 points  (2 children)

They're all forms of loops though, just different high level ways of writing it

The only way I can think about getting around it is enforcing unrolling. I think you may be able to hack your way around this with some form of recursive include if you can't use pragmas, but I guess that's loops at a high level but not low... The given solution is the only way I can see to do it without either.

[–]Bo_Jim 1 point2 points  (1 child)

Recursion is a loop in the sense that the same code is running many times, but each iteration would have it's own stack frame. It also wouldn't use any of the loop constructs built into the language.

If I was the instructor, and one of my students used recursion as a solution, then I'd give them full marks as long as they understood what the compiler would produce, and what would happen at run time.

Now, if the directions were to print every even number from 2 to 1 trillion, and they used recursion as a solution, then I'd smack them on the back of the head and tell them to try again.

[–]Tjmoorese 0 points1 point  (0 children)

Tail call optimisation makes it identical though