# Repeat lines until an event happens

**URL:** <https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753>\
**Category:** Coding Questions\
**Created:** [September 23, 2018, 8:32am UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753 "2018-09-23T08:32:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [September 23, 2018, 8:32am UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753/1 "2018-09-23T08:32:01Z")

</div>

Hello,  
I’m new here, and I’m simply searching for a way to repeat a line of code unlimited times (in one draw passing) until the wanted event happens. Is there any way to do so?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 23, 2018, 8:36am UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753/2 "2018-09-23T08:36:51Z")

</div>

Hi Schred,

That’s the goal of the `while` structure.

Check the reference: [https://processing.org/reference/while.html](https://processing.org/reference/while.html)

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [September 24, 2018, 1:00pm UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753/3 "2018-09-24T13:00:51Z")

</div>

Okay, thanks 😃

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [September 24, 2018, 1:31pm UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753/4 "2018-09-24T13:31:19Z")

</div>

What type of event? If we are talking about a key or mouse event, then you need to make sure `draw()` is not held hostage by your while loop as these types of events are queued and processed at the beginning of each cycle of `draw()`. If you don’t let `draw()` run normally, then you won’t be able to manage those input events properly.

Kf

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [September 24, 2018, 3:07pm UTC](https://discourse.processing.org/t/repeat-lines-until-an-event-happens/3753/5 "2018-09-24T15:07:58Z")

</div>

I managed to do it with the while() command. Thanks anyways 🙂
