Skip to main content
Known Participant
September 13, 2008
Question

JS Is there a way to abort endless loops?

  • September 13, 2008
  • 3 replies
  • 1712 views
Shame on me, but this happens. Ienter an endless loop and the whole computer is spinning off. If I kill the process, I'll lose unsaved changes. Is there any [poor] developer interrupt key to press to kill running scripts in ESTK2?

[Plus, I'd gladly see document recovery, oh well...]

regards,
m.
This topic has been closed for replies.

3 replies

moniuchAuthor
Known Participant
September 14, 2008
That's some workaround, thanks. Although I'd welcome an environment shortcut.

I found that when I'm testing a script for Adobe apps, it helps to have an alerts within such a loop. Even though one may call it a "crude debug", when a prompt comes up within Adobe app, I am able to switch to ESTK and press stop. That saves the butt too.

m.
Harbs.
Legend
September 14, 2008
I've never tried with Illustrator, but in InDesign the escape key will
break out of a script.

Harbs
try67
Community Expert
Community Expert
September 14, 2008
Another option, use $.bp(condition);
If condition is true, the script stops.
try67
Community Expert
Community Expert
September 14, 2008
I don't think you can stop a running JavaScript except by closing the application. What you can do is to add an artificial upper limit, so let's say you have a while loop,

while (condition) { /*do something*/ }

Then you can change it to:
var i=0;
while (condition && i<1000000) { /*do something*/; i++;}
if (i==1000000) { /* Present some error message */ }

It's not the best solution in the world, but it will at least guarantee that you won't get into an endless loop.