# Label is not updated inside a for loop

**URL:** <https://discourse.processing.org/t/label-is-not-updated-inside-a-for-loop/43018>\
**Category:** Libraries\
**Created:** [October 20, 2023, 7:59am UTC](https://discourse.processing.org/t/label-is-not-updated-inside-a-for-loop/43018 "2023-10-20T07:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Luis](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@Jose\_Luis](https://discourse.processing.org/u/Jose_Luis)\
**Post date:** [October 20, 2023, 7:59am UTC](https://discourse.processing.org/t/label-is-not-updated-inside-a-for-loop/43018/1 "2023-10-20T07:59:55Z")

</div>

I try to update a label inside a for loop but it is not updated until the loop ends, I use processin 4.3 G4P GUI Builder 4.4.2 on linux Mint  
my code is the following

```auto
public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:431015:
  if(event == GEvent.CLICKED){
  for (int a =1; a<=20;a++){
    String b = str(a);
    label1.setText(b);
    label1.forceBufferUpdate();
    delay (500);
  }
  }
} //_CODE_:button1:431015:

```

Could someone explain to me what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2023, 9:42am UTC](https://discourse.processing.org/t/label-is-not-updated-inside-a-for-loop/43018/2 "2023-10-20T09:42:20Z")

</div>

no mistake on your side

the screen is not updated throughout but only once at the end of draw(). _Big Processing principle._

this goes for all animations and stuff: don’t use _for-loops_ but the fact that draw loops automatically.

You can replace the for-loop with a structure in draw().

Chrisir 🙂

**Example**

```auto

int counter = 0;

void setup() {
  size(700, 700);
}

void draw() {
  background(0);

  if (counter<=20) {
    String textOutput = str(counter);
    text(textOutput, 22, 22);
    delay (500);

    counter++;
  } else {
    text("Loop is over.", 22, 22);
  }//else
  //
} //

```
