23
6
For
loops are used extensively in many languages, but what would you do if no languages supported them?
Create a way to execute a basic for
loop without using any repetition structures (for
, foreach
, while
, do
, etc).
The basic for loop that you need to replicate is set up like this
for(i=0;i<1000;i++)
You must be able to replicate this without using repetition structures. It must also execute code in your language that would be in the body of the loop. Any form of eval
is allowed, though it may not execute the for
loop on its own.
You can test your code by having it print i
with a space 100 times, add this test case to the end of your answer to verify your code with others.
There are no restrictions on what exactly it has to be, all it needs to do is replicate the for
loop.
Winner will be decided based on upvotes at the time that it is chosen.
100 times or 1000? Or 100 000 times? – user unknown – 2011-02-19T06:50:15.483
I am voting to close this as off-topic because we require objective validity criteria for all challenges. As it stands, there is no clear way to determine the validity of a submission. Additionally, there is no specification of the behavior of a valid submission. – Mego – 2016-05-20T05:35:26.247
10I find the problem too undefined. You say “without using any repetition structures” and only give examples (but not an extensive list) of such prohibited structures. The answers provided so far use recursion or goto, both of which I would classify as “repetition structures”, but it can be debated. Without a proper definition of what is allowed and what isn’t, this question is not interesting. – Timwi – 2011-03-08T14:34:20.167
gotos, recursion... – Mateen Ulhaq – 2011-03-10T02:29:20.703