# How to exit/end event script early?

**URL:** <https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 24, 2023, 10:14pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818 "2023-07-24T22:14:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [July 24, 2023, 10:14pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/1 "2023-07-24T22:14:04Z")

</div>

Is it possible to stop the execution of an event script or exit early without disastrous side effects?

For instance, I have a few IF statements and would like to exit the script if any of them return "True", rather than attempting to nest them in the correct order and break up the finishing code...

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 24, 2023, 10:18pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/2 "2023-07-24T22:18:49Z")

</div>

> [@mdemaris](#):
>
> ... and would like to exit the script if any of them return "True",

That's best practice. And, of course, you can return on false or any other condition.

I recommend [Why you shouldn't nest your code](https://www.youtube.com/watch?v=CFRhGnuXG-4&pp=ygUMbmV2ZXIgbmVzdGVy) on Youtube. It's not written specifically for Python but the principles are the same and it might just revolutionise your coding style.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [July 24, 2023, 10:26pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/3 "2023-07-24T22:26:18Z")

</div>

Let's say button click event:

```auto
if a = 1:
   send message to user, wrong number
   exit event script...
if b = 2:
   send message, wrong number
   exit event script
Add a few more if's

```

If the code makes it through the above checks,  
then we should run the following code:

```auto
do lots of stuff

```

exit event naturally

How can I exit/end event on line 3 instead of at the end of the code? That's what I'm looking for

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 24, 2023, 10:26pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/4 "2023-07-24T22:26:32Z")

</div>

Just `return`.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 24, 2023, 10:35pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/5 "2023-07-24T22:35:02Z")

</div>

```auto
if a == 1:
   # send message to user, wrong number
   return
if b == 2:
   # send message, wrong number
   return

# Otherwise ...

```

Note well the use of the **==** equivelance operator rather than the **=** set operator. There's a big difference.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [July 24, 2023, 10:38pm UTC](https://forum.inductiveautomation.com/t/how-to-exit-end-event-script-early/76818/6 "2023-07-24T22:38:33Z")

</div>

I just got `return` from that video and put it into the code, lol.

Thanks!
