Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JS Is there a way to abort endless loops?

New Here ,
Sep 13, 2008 Sep 13, 2008
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.
TOPICS
Scripting
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 14, 2008 Sep 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2008 Sep 14, 2008
Another option, use $.bp(condition);
If condition is true, the script stops.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2008 Sep 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2008 Sep 14, 2008
LATEST
I've never tried with Illustrator, but in InDesign the escape key will
break out of a script.

Harbs
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines