Like Peter said, there's the CMD-. shortcut to break infinite loops.
And if that doesn't work and the image crashes, you still typically don't lose a lot of work. Don't forget, that every time you save (accept) a single method, that change is written to the .changes file. Even if you haven't saved the image before it crashes, you can use the��
'World > Tools... > Recover lost changes' tool to recover a lot of your work. (Since you've been contributing to the UPBE book, take a look at the 'How to get your code back' section in the Environment chapter :) ).