How can the loop be stopped after one cycle?

Of course. That first line should be

const byte buttonPin = 5; // the pin number.

That happens more with such entirely untested code examples :slight_smile: