A question similar to this has been asked a couple of years ago, but this one is even trickier.
The challenge is simple. Write a program (in your language of choice) that repeatedly executes code without using any repetition structures such as while
, for
, do while
, foreach
or goto
(So for all you nitpickers, you can't use a loop). However, recursion is not allowed, in the function calling itself sense (see definition below). That would make this challenge far too easy.
There is no restriction on what needs to be executed in the loop, but post an explanation with your answer so that others can understand exactly what is being implemented.
For those who may be hung up on definitions, the definition of a loop for this question is:
A programming language statement which allows code to be repeatedly executed.
And the definition of recursion for this question will be your standard recursive function definition:
A function that calls itself.
Winner will be the answer that has the most upvotes on July 16th at 10 AM eastern time. Good luck!
UPDATE:
To calm confusion that is still being expressed this may help:
Rules as stated above:
- Don't use loops or goto
- Functions cannot call themselves
- Do whatever you want in the 'loop'
If you want to implement something and the rules don't explicitly disallow it, go ahead and do it. Many answers have already bent the rules.
function A
callsfunction B
andfunction B
callsfunction A
while 1 of the functions performs something. Since the function doesn't call itself it should be valid based on the criteria ^.^ \$\endgroup\$rep(f){f();f();}
- this is a statement (a function declaration is a statement in some languages) that allows executing code repeatedly. Is it disallowed. You ask for code to implement a loop. If that code is syntactically a statement, you have just disallowed it. Another example:f(b) { b(); g(b); }; g(b) { f(b); }
. I'd sayf
is a recursive function (by being mutually recursive withg
). Is it disallowed? \$\endgroup\$