# Never ending loop

**URL:** https://discourse.processing.org/t/never-ending-loop/13990
**Category:** Beginners
**Created:** [September 14, 2019, 5:16pm UTC](https://discourse.processing.org/t/never-ending-loop/13990 "2019-09-14T17:16:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [September 14, 2019, 5:16pm UTC](https://discourse.processing.org/t/never-ending-loop/13990/1 "2019-09-14T17:16:08Z")

</div>

Why a loop is never ending a you use de function random as in:

```auto
for (int i = 0; i < 1000; i = i+1)
             {
               A = random(i);
               B = random(i);
                point(A,B);
             }

```

And how can you make it end

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [September 14, 2019, 5:32pm UTC](https://discourse.processing.org/t/never-ending-loop/13990/2 "2019-09-14T17:32:15Z")

</div>

the for loop is assigned to choosing a value in the x and y, not to dictating how long the loop runs for. It runs in draw which is an infinite for loop, and therefore it never ends.

If that’s what you wanted you would need a if statement to handle the time constraint.

```auto

void setup(){
  size(200,200);
}
int j = 0;
void draw(){
  if (j<100){
  for (int i = 0; i < 100; i ++)
{
float A = random(i);
float B = random(i);
point(A,B);
}}
j++;
}

```

---

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [September 14, 2019, 7:55pm UTC](https://discourse.processing.org/t/never-ending-loop/13990/3 "2019-09-14T19:55:52Z")

</div>

> [@paulgoux](#):
>
> void setup(){ size(200,200); } int j = 0; void draw(){ if (j\<100){ for (int i = 0; i \< 100; i ++) { float A = random(i); float B = random(i); point(A,B); }} j++; }

Thank you veru much…

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [September 14, 2019, 7:59pm UTC](https://discourse.processing.org/t/never-ending-loop/13990/4 "2019-09-14T19:59:52Z")

</div>

> [@Ignaki](#):
>
> how can you make it end

> [@paulgoux](#):
>
> It runs in draw which is an infinite for loop

Another way is to call `noLoop()` in setup. Then draw runs only once, with no loop, so your `for` loop runs only once, not 60fps.

- [noLoop() / Reference / Processing.org](https://processing.org/reference/noLoop_.html)
