News for hackers. Stuff that matters.
Re:Stack Overflow: Printing 1 to 1000 in C by ajays on Monday March 14, 2011 @02:02PM (#2323612)
Isn't "upto" a loop? The idea, IIRC, is to print the numbers without loops and conditionals.
Re:Stack Overflow: Printing 1 to 1000 in C by jerf on Monday March 14, 2011 @03:08PM (#2323915)
It "can be" implemented recursively. If you're going to be pedantic about this (and who doesn't love being pedantic?) you need to be very careful about your definitions, because regardless of what you write you're going to have jump instructions in the finally-executed machine code. If you say that you can't have a loop "anywhere", you're limited to recursion, and then what will you do when someone comes along and points out that recursion and looping are ultimately equivalent? This is one of those cases where examining the boundary too closely makes it dissolve under the scrutiny, and it's better just to smile and nod and play along (and have fun arguing).
Re:Stack Overflow: Printing 1 to 1000 in C by 3pt14159 on Monday March 14, 2011 @02:14PM (#2323671)
1.upto(10).class => Enumerator
Re:Stack Overflow: Printing 1 to 1000 in C by tptacek on Monday March 14, 2011 @02:50PM (#2323848)
That's like doing:

  #define NOT_A_LOOP(x) while(x)
Enumerator is just Ruby object goo over a loop.
Re:Stack Overflow: Printing 1 to 1000 in C by 3pt14159 on Monday March 14, 2011 @08:05PM (#2325118)
More like:

#include someone_else_did_it_so_we_dont_know(x)

Just as those other answers in C relied on GOTOs somewhere.

Re:Stack Overflow: Printing 1 to 1000 in C by jluxenberg on Monday March 14, 2011 @03:35PM (#2324041)
puts ((1..1000).to_a.join("\n"))

Which, of course, is passing the buck to Range#to_a