# How often does the draw function loop?

**URL:** <https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721>\
**Category:** Beginners\
**Created:** [March 22, 2021, 11:31am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721 "2021-03-22T11:31:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex3](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@alex3](https://discourse.processing.org/u/alex3)\
**Post date:** [March 22, 2021, 11:31am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721/1 "2021-03-22T11:31:33Z")

</div>

Hi, I’m new to processing and I noticed my draw function was looping. Does this always happen and if so how many times does it loop?

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 22, 2021, 11:37am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721/2 "2021-03-22T11:37:00Z")

</div>

Yes, the `draw()` function runs over and over again, and each time it finishes, what is displayed in your sketch is updated. It runs as fast as it can, but no faster than the frame rate is set to. Typically it will redraw your sketch 60 times a second.

Realize that it’s not “looping”, but running over and over again.

It will run over and over again until the sketch is closed, either by pressing the X on the window, killing it, or you call `exit()`.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [March 22, 2021, 11:40am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721/3 "2021-03-22T11:40:54Z")

</div>

Hi,

Welcome to the community! 😉

> [@alex3](#):
>
> Does this always happen

Yes it always happen luckily for us! Unless you use the [`noLoop()`](https://processing.org/reference/noLoop_.html) function which stops the loop.

As @TfGuy44 said, most of the time it’s running around 60 fps. You can check this by printing the [`frameRate`](https://processing.org/reference/frameRate.html) variable :

```auto
void draw() {
  println(frameRate);
}

```

From the documentation :

> The system variable **frameRate** contains the approximate frame rate of a running sketch. The initial value is 10 fps and is updated with each frame. The value is averaged over several frames, and so will only be accurate after the draw function has run 5-10 times.

And also the `draw()` function page : [draw() / Reference / Processing.org](https://processing.org/reference/draw_.html)

> Called directly after **setup()** , the **draw()** function continuously executes the lines of code contained inside its block until the program is stopped or **noLoop()** is called. **draw()** is called automatically and should never be called explicitly. All Processing programs update the screen at the end of draw(), never earlier.

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [March 23, 2021, 10:15am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721/4 "2021-03-23T10:15:15Z")

</div>

Welcome to the Processing community, @alex3!

If you wish to change the rate of repetition of the `draw()` function, you can call the `frameRate()` function, passing the desired number of frames per second as an argument. Here is an example:

```auto
void setup() {
  size(480, 360);
  frameRate(10);
}

```

See [Processing Reference: frameRate()](https://processing.org/reference/frameRate_.html).

_Edited on March 23, 2021 to clarify the explanation._

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 23, 2021, 10:37am UTC](https://discourse.processing.org/t/how-often-does-the-draw-function-loop/28721/5 "2021-03-23T10:37:06Z")

</div>

Hello,

_Lots of resources (tutorials, examples, references, etc.) available here:_  
_[https://processing.org/](https://processing.org/)_

You are asking about draw():  
[https://processing.org/reference/draw\_.html](https://processing.org/reference/draw_.html)

This also has related references on the page such as:  
_[setup() \ Language (API) \ Processing 3+](https://processing.org/reference/setup_.html)_  
_[frameRate() \ Language (API) \ Processing 3+](https://processing.org/reference/frameRate_.html)_  
And others…

And so your journey begins…

`:)`
