Denial of responsibility:
There is no perfect way to do this. If you can stand this true fact, then feel free to continue.
There are several ways to do this.
With repeat until
The first and simplest of them follows:

But this is not technically part of the script - it simply repeats until some value returns true.
With custom block ( stop this script )
To do this inside the script, you need to use a hidden little trick with custom blocks.
Create the custom block you want, but perhaps along the lines of the "breakable loop". Inside this, create this script:

Using the stop script , we exit the script that is currently running, which, according to Scratch, is a custom block.
See the result! (like notepads)
With broadcast and wait
You can also use the broadcast and wait method, very similar to the above:

Although I strongly recommend that you do not use this method as if other sprites had intermittent loops, you will need to rename them, which can be tedious after using many loops in many sprites!
(Note that this error was fixed in the editor version 442 of the editor, and this procedure is no longer applied.)
Help! My project is already falling off!
As @foi noted , if your code should be running inside a frame that you probably checked , run without refreshing the screen . Unfortunately, due to an error in the Scratch player, this causes the program to crash significantly after the stop this script block has been activated. How can you handle this?

It follows the same principle that you use when running without a custom screen update block inside the forever loop - the loop does not use screen refresh while working inside, which allows instant animation regardless of using turbo mode .
Here's an example - the image is too long to be embedded, so see here .