News for hackers. Stuff that matters.
Re:Display 100 Hello World Without Using Loops by sad on Friday May 25, 2012 @10:57AM (#4023752)
These are fun.

In C++, make the compiler do your recursion:

  #include <iostream>

  template <int N>
  void pr(const std::string &msg)
  {
      std::cout << msg << std::endl;
      pr<N-1>(msg);
  }

  template <>
  void pr<0>(const std::string &msg)
  {
  }

  int main(int argc, char *argv[])
  {
      pr<100>("Hello World");
      return 0;
  }

There are no comments on this comment yet.