How to break out of a script

49 views
Skip to first unread message

GregC

unread,
Sep 11, 2021, 12:58:21 AM9/11/21
to mozilla-rhino
If I have a simple script and want to write

if (blah) {
    return;
}
doThis();
doThat();


Then Rhino throws an error " invalid return (<>#9)"

So I can't use the return keyword, what can I use to exit the script?

thanks!

Tony Germano

unread,
Oct 5, 2021, 7:46:48 PM10/5/21
to mozilla-rhino
Put it in a function?

(function() {
    if (blah) {
        return;
    }
    doThis();
    doThat();
})();

If you are in a Rhino shell context, there is the quit(exitCode) function you can call instead of return.

Merten Schumann

unread,
Oct 7, 2021, 1:22:03 AM10/7/21
to mozill...@googlegroups.com

you could change the control flow ...

 

if (!blah) {

   doThis();

   doThat();

}

 

:-)

   Merten

 

From: mozill...@googlegroups.com <mozill...@googlegroups.com> On Behalf Of GregC
Sent: Saturday, September 11, 2021 6:58 AM
To: mozilla-rhino <mozill...@googlegroups.com>
Subject: [mozilla-rhino] How to break out of a script

 

*** External email: Verify sender before opening attachments or links ***

 

--
You received this message because you are subscribed to the Google Groups "mozilla-rhino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-rhin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mozilla-rhino/75700822-678a-4dd3-b85d-844346443436n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages