Implements exercises 32-35 (loops)