# Array reset help

**URL:** <https://discourse.processing.org/t/array-reset-help/20423>\
**Category:** Coding Questions\
**Created:** [May 3, 2020, 9:13am UTC](https://discourse.processing.org/t/array-reset-help/20423 "2020-05-03T09:13:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://discourse.processing.org/u/Dylan)\
**Post date:** [May 3, 2020, 9:13am UTC](https://discourse.processing.org/t/array-reset-help/20423/1 "2020-05-03T09:13:53Z")

</div>

I’m trying to have the array reset all of the numbers to random numbers when I press the ‘r’ key but it’s not working

```auto
int many=20;
int[] array = new int[many];

void setup() {
  size(640, 480);
}
void draw() {
  scene();
  // controls();
  // showAll();
  reset(array, many);
  show(array, many);
  noLoop();
}

void reset(int[] a, int m) {
  for (int i=0; i<m; i++) {
    a[i] = int(random(0, 1000));
  }
}
void show(int[] a, int m) {
  for (int i=0; i<m; i++) {
    textSize(16);
    text(a[i], 75, 70+i*15);
  }
}
void scene() {
  background(195, 103, 207);
  textSize(24);
  // text( title, 275, 25);
  textSize(18);
  text( " Numbers ", 45, 45);
  // text( " Controls ", 225, 45);
}
void keyPressed() { 
  if (key == 'q') exit(); 
  if (key == 'r') reset(array, many);
}

```

---

<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:** [May 3, 2020, 9:21am UTC](https://discourse.processing.org/t/array-reset-help/20423/2 "2020-05-03T09:21:25Z")

</div>

That `noLoop()` at the end of draw is screwing you over. You are resetting the array succesfully, but because of `noLoop()`, the sketch is not redrawn.

This means you `reset()` the array in `draw`, show it and then stop drawing forever. So even if you change the values of `array`, they won’t be shown on-screen.

To fix this, move `reset(array)` into `setup` and remove the `noLoop()` from `draw`.

Also, you don’t need the variable `many` to keep track of the amount of elements, because every array has an inbuilt `length` variable that tells you exactly that and can be accessed like this: `array.length`.

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://discourse.processing.org/u/Dylan)\
**Post date:** [May 3, 2020, 9:26am UTC](https://discourse.processing.org/t/array-reset-help/20423/3 "2020-05-03T09:26:51Z")

</div>

Thanks for the help and the tip!

I didn’t realize that `noLoop()` meant to stop drawing forever.

---

<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:** [May 3, 2020, 11:15am UTC](https://discourse.processing.org/t/array-reset-help/20423/4 "2020-05-03T11:15:56Z")

</div>

> [@Dylan](#):
>
> … **noLoop()** meant to stop drawing forever.

> **[loop() / Reference](https://processing.org/reference/loop_.html)**
>
> By default, Processing loops through draw() continuously, executing the code within it. However, the draw() loop may be stopped by calling noLoop(). In that case, the draw()

> **[redraw() / Reference](https://processing.org/reference/redraw_.html)**
>
> Executes the code within draw() one time. This functions allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or
