Convert loop.rst into a tutorial