# Can't print IntList outside setup function

**URL:** https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965
**Category:** Beginners
**Created:** [March 29, 2021, 10:19pm UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965 "2021-03-29T22:19:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![potter3366](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@potter3366](https://discourse.processing.org/u/potter3366)
#### Post date: [March 29, 2021, 10:19pm UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965/1 "2021-03-29T22:19:44Z")

</div>

I can print listaA within setup function but not when I press a “w” key. Why?

```auto
IntList Ptop;
final int ROWS = 8;
final IntList[] listaA = new IntList[ROWS];
int value;
int index;

void setup() {
  size(520, 220);

  Ptop = new IntList();

  Ptop.append(new int[] {-1, -1, -1, -1, 5, 11, 8, 11, 7, 11, 6, 11, 5, 12, 9, 12, 3, 12, 2, 12, 0, -2, -2, -2, -2});
  println(Ptop);

  for (int value=6; value<=20; value=value+2) {
    index = 0;
    listaA[index] = new IntList();
    for (int i=value; i<Ptop.size(); i=i+1) {
      listaA[index].append(Ptop.get(i));
    }
    for (int i=value-2; i>=0; i=i-1) {
      listaA[index].append(Ptop.get(i));
    }
    println(listaA[index]);
    index++;
  }
}

void keyReleased() {
  if (key == 'w') {
    for (int k=0; k<8; k++) {
      println(listaA[k]);
    }
  }
}

```

---

<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 29, 2021, 11:33pm UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965/3 "2021-03-29T23:33:45Z")

</div>

Hi,

Welcome to the forum! 😉

As @glv said, the Processing reference is the way to go if you have any questions concerning the functions and methods!

From the `keyReleased()` page :

> Mouse and keyboard events only work when a program has **draw()**. Without **draw()** , the code is only run once and then stops listening for events.

---

<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 29, 2021, 11:40pm UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965/5 "2021-03-29T23:40:36Z")

</div>

Yes @glv, sorry! 😉

My joy of discovery is too strong ahah

---

<div class="post-metadata">

### Author: ![potter3366](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@potter3366](https://discourse.processing.org/u/potter3366)
#### Post date: [March 30, 2021, 9:23am UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965/6 "2021-03-30T09:23:19Z")

</div>

When I add draw() function, I have the following problem:

Only one listaA is printed, others are null:

IntList size=24 [0, -2, -2, -2, -2, 2, 12, 3, 12, 9, 12, 5, 11, 6, 11, 7, 11, 8, 11, 5, -1, -1, -1, -1]  
null  
null  
null  
null  
null  
null  
null

---

<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 30, 2021, 11:03am UTC](https://discourse.processing.org/t/cant-print-intlist-outside-setup-function/28965/7 "2021-03-30T11:03:56Z")

</div>

Hello,

```auto
for (int value=6; value<=20; value=value+2) 
    {
    index = 0;
    
   //Your code

    println(index, listaA[index]); // Added index so you can see which what code is doing.
    index++;
  }

```

For starters…

You are setting index to 0 at the start of each loop.  
Your code is doing what you programmed it to do and that is why they are _null_ after _index = 0;_

`:)`
