title: C++: purpose of for(;;)?
body: <p>I just wanted to know the reasoning for the line <code>for(;;)</code> in the following code.</p>
  
  <pre><code>//
  // blocking_tcp_echo_server.cpp
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //
  // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  //
  // Distributed under the Boost Software License, Version 1.0. (See accompanying
  // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  //
  
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/smart_ptr.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/thread/thread.hpp&gt;
  
  using boost::asio::ip::tcp;
  
  const int max_length = 1024;
  
  typedef boost::shared_ptr&lt;tcp::socket&gt; socket_ptr;
  
  void session(socket_ptr sock)
  {
    try
    {
      for (;;)
      {
        char data[max_length];
  
        boost::system::error_code error;
        size_t length = sock-&gt;read_some(boost::asio::buffer(data), error);
        if (error == boost::asio::error::eof)
          break; // Connection closed cleanly by peer.
        else if (error)
          throw boost::system::system_error(error); // Some other error.
  
        boost::asio::write(*sock, boost::asio::buffer(data, length));
      }
    }
    catch (std::exception&amp; e)
    {
      std::cerr &lt;&lt; "Exception in thread: " &lt;&lt; e.what() &lt;&lt; "\n";
    }
  }
  
  void server(boost::asio::io_service&amp; io_service, short port)
  {
    tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
    for (;;)
    {
      socket_ptr sock(new tcp::socket(io_service));
      a.accept(*sock);
      boost::thread t(boost::bind(session, sock));
    }
  }
  
  int main(int argc, char* argv[])
  {
    try
    {
      if (argc != 2)
      {
        std::cerr &lt;&lt; "Usage: blocking_tcp_echo_server &lt;port&gt;\n";
        return 1;
      }
  
      boost::asio::io_service io_service;
  
      using namespace std; // For atoi.
      server(io_service, atoi(argv[1]));
    }
    catch (std::exception&amp; e)
    {
      std::cerr &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; "\n";
    }
  
    return 0;
  }
  </code></pre>