move loop inside case stmt