solutions to exercises of chapter loop