If reached a certain frame - stop

Hi, can you, please help me with this. I have a button, it functions like this

on (release) {
nextFrame();

I want this action stop at a certain frame. So nothing happens when you click a button when it reached a certain frame.

Thank you.