# Making a for loop ( or timer )

**URL:** <https://discourse.processing.org/t/making-a-for-loop-or-timer/6483>\
**Category:** Coding Questions\
**Created:** [December 10, 2018, 4:45pm UTC](https://discourse.processing.org/t/making-a-for-loop-or-timer/6483 "2018-12-10T16:45:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunnylimenoid](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Sunnylimenoid](https://discourse.processing.org/u/Sunnylimenoid)\
**Post date:** [December 10, 2018, 4:45pm UTC](https://discourse.processing.org/t/making-a-for-loop-or-timer/6483/1 "2018-12-10T16:45:56Z")

</div>

Hello, I am new to processing, but have been trying to figure out how to implement a for loop for my code below. I have only used while loops before, so i’m not used to for loops, but I’m told that they are efficient and more powerful. I want to use a for loop to run my program for only 15 seconds from the start, and once those 15 seconds have passed, then it starts over from the beginning, looping as such. I’m lost, because I used recursion, and don’t know how to make a for loop that works without errors. Please direct me in the right direction. Thanks.

```auto
float a = 5;
int x = 0;

void setup() {
  size(700,500);
  background(255,244,206);
  smooth();
  noStroke();
 
}
 
void draw() {
  drawCircle(width/2,height/2,200);
  if (x < 100) {
    x = x + 1;
  } else {
    noLoop();
  }
  // Saves each frame as line-000001.png, line-000002.png, etc.
  saveFrame("line-######.png");

  } 
 
 void drawCircle(float x, float y, float radius) {
  stroke(0);
  fill(247,80,91);
  rotate(a);
  ellipse(x, y, radius, radius);
  if(radius > 2) {
    a = a + 0.1;
    drawCircle(x + radius/2, y, radius/2);
    drawCircle(x - radius/2, y, radius/2);
    drawCircle(x, y + radius/2, radius/2);
    drawCircle(x, y - radius/2, radius/2);
  
  }
}

```

---

<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:** [December 10, 2018, 4:58pm UTC](https://discourse.processing.org/t/making-a-for-loop-or-timer/6483/2 "2018-12-10T16:58:12Z")

</div>

a simple timer only:

```auto
// ..
long startT, stopT=15000;

void setup() {
// ..
  startT = millis();
}

void draw() {
//...
  if ( millis() > startT + stopT ) {
    startT = millis();
    println("_next loop_");
    // do some reset her....
    background(255, 244, 206);
  }
} 

```
