# Question on quirks of loop() and noLoop() and control of draw() iterations

**URL:** <https://discourse.processing.org/t/question-on-quirks-of-loop-and-noloop-and-control-of-draw-iterations/43872>\
**Category:** p5.js\
**Created:** [February 10, 2024, 3:34am UTC](https://discourse.processing.org/t/question-on-quirks-of-loop-and-noloop-and-control-of-draw-iterations/43872 "2024-02-10T03:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grege2](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/grege2/32/3069_2.png) [@grege2](https://discourse.processing.org/u/grege2)\
**Post date:** [February 10, 2024, 3:34am UTC](https://discourse.processing.org/t/question-on-quirks-of-loop-and-noloop-and-control-of-draw-iterations/43872/1 "2024-02-10T03:34:58Z")

</div>

Hi all,

An elementary question but it has me puzzled, after all this time using p5.js.

There seem to some odd quirks of loop() and noLoop(). Please see [p5.js Web Editor](https://editor.p5js.org/grege2/sketches/M4He0op7F)

It seems that loop() can force one, or two, runs of draw() (but no more).

Is there any sense that loop() calls are stacked ? If so, can isLooping() return the number of iterations remaining that draw() is going to do.

I tried to search the p5.js code about this but couldn’t find the real implementation code of loop(), noLoop(), isLooping(). If you can point me to that I’d be grateful.

Cheers.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 10, 2024, 6:40am UTC](https://discourse.processing.org/t/question-on-quirks-of-loop-and-noloop-and-control-of-draw-iterations/43872/2 "2024-02-10T06:40:08Z")

</div>

> [@grege2](#):
>
> … but couldn’t find the real implementation code of **loop()**, **noLoop()**, **isLooping()**.

> <https://github.com/processing/p5.js/blob/v1.9.0/src/core/structure.js#L124-L131>

> <https://github.com/processing/p5.js/blob/v1.9.0/src/core/structure.js#L78-L80>

> <https://github.com/processing/p5.js/blob/v1.9.0/src/core/structure.js#L188-L190>

---

<div class="post-metadata">

**Author:** ![grege2](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/grege2/32/3069_2.png) [@grege2](https://discourse.processing.org/u/grege2)\
**Post date:** [February 10, 2024, 10:11am UTC](https://discourse.processing.org/t/question-on-quirks-of-loop-and-noloop-and-control-of-draw-iterations/43872/3 "2024-02-10T10:11:18Z")

</div>

Thanks @GoToLoop, that’s very helpful. Don’t know why I didn’t find the real loop() / noLoop() code. Will check more better. Ciao for now.
