# The screen is updating after while loop is completed ? need help

**URL:** https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119
**Category:** Beginners
**Created:** [January 2, 2019, 9:52pm UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119 "2019-01-02T21:52:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![liceroy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/liceroy/32/3047_2.png) [@liceroy](https://discourse.processing.org/u/liceroy)
#### Post date: [January 2, 2019, 9:52pm UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119/1 "2019-01-02T21:52:07Z")

</div>

I am using " delay() " inside while loop and making some changes in the screen. I was hoping the changes will be visiable since I am using delay(1000) in every while loop but only the final result is printed on screen . I am not doing anything inside draw function. I am trying to make a event based system where user can interact with just mouse and keyboard.

I want to run while loop such that it will show me the changes I made on screen after every iteration for 1sec then proceed forward.

my code is something like this

```auto
while(){
…
…

delay(1000);

..
..

}

```

---

<div class="post-metadata">

### Author: ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)
#### Post date: [January 2, 2019, 10:08pm UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119/2 "2019-01-02T22:08:05Z")

</div>

The rects(),and every shape,text… is displayed everytime draw() is called, this means everything u change in your while, cant be seen until your while terminates and draw() is called once again.  
" **draw()** is called automatically and should never be called explicitly. All Processing programs update the screen at the end of draw(), never earlier. "  
[https://processing.org/reference/draw\_.html](https://processing.org/reference/draw_.html)

“The screen only updates when the end of **draw()** is reached, so **delay()** cannot be used to slow down drawing. For instance, you cannot use **delay()** to control the timing of an animation.”  
[https://processing.org/reference/delay\_.html](https://processing.org/reference/delay_.html)

If you want to “slow” the draw() function, you can use frameRate(num\_of\_frame\_per\_sec)  
(Default is 60fps)  
[https://processing.org/reference/frameRate\_.html](https://processing.org/reference/frameRate_.html)

(I hope I didnt misunderstood your problem)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 3, 2019, 1:08am UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119/3 "2019-01-03T01:08:06Z")

</div>

here a example using a millis timer:

```auto
long startT, stopT=1000;
float ang = 0;
float colc;
color rf;

void setup() {
  size(500, 500);
  colc=random(255);
  rf=color(colc, 0, 255-colc);
}

void myTimer() {
  if ( millis() > startT + stopT ) {
    startT = millis();
    println("_next loop_");
    // what else you need to be done now?
    ang++;
    colc=random(255);
    rf=color(colc, 0, 255-colc);
  }
} 

void draw() {
  background(255, 244, 206);  
  myTimer();
  translate(width/2, height/2);
  rotate(ang *TWO_PI/60.0);
  draw_object();
}

void draw_object() {
  stroke(0, 0, 200);
  line(0, 0, 50, 50);
  fill(rf);
  rect( 50, 50, 20, 20);
}

```

---

<div class="post-metadata">

### Author: ![liceroy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/liceroy/32/3047_2.png) [@liceroy](https://discourse.processing.org/u/liceroy)
#### Post date: [January 20, 2019, 6:37pm UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119/4 "2019-01-20T18:37:50Z")

</div>

@Sky

Sorry for replying late , I was busy implementing max heap and some other stuff in processing. I didn’t knew that screen was updated after draw() xD .

The problem is now solved, thanks you.

---

<div class="post-metadata">

### Author: ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)
#### Post date: [January 20, 2019, 7:36pm UTC](https://discourse.processing.org/t/the-screen-is-updating-after-while-loop-is-completed-need-help/7119/5 "2019-01-20T19:36:28Z")

</div>

No problem, I’m glad you solved the problem
