# Looping a script while tag is on

**URL:** <https://forum.inductiveautomation.com/t/looping-a-script-while-tag-is-on/93402>\
**Category:** Ignition\
**Created:** [July 18, 2024, 3:06pm UTC](https://forum.inductiveautomation.com/t/looping-a-script-while-tag-is-on/93402 "2024-07-18T15:06:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 18, 2024, 3:31pm UTC](https://forum.inductiveautomation.com/t/looping-a-script-while-tag-is-on/93402/2 "2024-07-18T15:31:32Z")

</div>

Welcome to the forum, Jason.

Tips:  
Have a look at [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). It will then render as (but I'm guessing your indentation):

```python
def transform(self, value, quality, timestamp):
    while value == True:
        self.getChild("Audio20").props.play = True
        import time
        time.sleep(30)
    else:
        self.getChild("Audio20").props.play = False
    return value

```

- Pretty much any time you are using `sleep()` in a script you are doing something wrong.
- You have `import time` inside a while loop. It should be outside so it only happens once (but you shouldn't be using `sleep()` anyway).
- You have an `else` statement with no `if`. (See @pascal.fragnoud's comment below.)
- `while value == True:` can be reduced to `while value:`.

---

_[View the full topic](https://forum.inductiveautomation.com/t/looping-a-script-while-tag-is-on/93402)._
