# How can I run a for loop using a function?

**URL:** https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403
**Category:** Coding Questions
**Created:** [January 28, 2020, 10:27pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403 "2020-01-28T22:27:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Daniele92](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@Daniele92](https://discourse.processing.org/u/Daniele92)
#### Post date: [January 28, 2020, 10:27pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403/1 "2020-01-28T22:27:34Z")

</div>

Hello to everyone. Can someone explain to me , How can I run a :

```auto
for( int i=100; i>0; i=i-10 ) {
ellipse(100,100,i,i); 
}

```

Using a function?!  
Thank you , i DON’t want a code but need to understand for classroom activity.

---

<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: [January 28, 2020, 10:33pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403/2 "2020-01-28T22:33:19Z")

</div>

for using a function you need a full sketch with setup and draw and your new function.

For `setup()` and `draw()` see [https://www.processing.org/tutorials/overview/](https://www.processing.org/tutorials/overview/)

A function can be inserted at different levels of your sketch: You could either

- replace ellipse(100,100,i,i); with a function (named `myEllipse(float i)`) that gets i as a parameter OR
- replace your entire code (all three lines) with a function (`ellipseArt()`) without parameters.

More about functions: see [https://github.com/Kango/Processing-snippets/wiki/programming-and-functions](https://github.com/Kango/Processing-snippets/wiki/programming-and-functions)

---

<div class="post-metadata">

### Author: ![Daniele92](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@Daniele92](https://discourse.processing.org/u/Daniele92)
#### Post date: [January 28, 2020, 10:49pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403/3 "2020-01-28T22:49:29Z")

</div>

To be honest I’m newbie ( first three months of experience)

```auto
void setup() {
  size(500,300);
  background(255);
  for(int i=100; i>0; i=i-10) { 
    ellipse(100,100,i,i);
  }
}

void draw() {
   
}

```

Should I create a function calling ABC… with int/void? I really want to improve My self. Can you pls do some Example?

---

<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: [January 28, 2020, 10:58pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403/4 "2020-01-28T22:58:46Z")

</div>

```auto

void setup() {
  size(500, 300);
  background(0);
}

void draw() {
  background(0);
  for (int i=100; i>0; i=i-10) {
    myEllipse(i);
  }
}

void myEllipse(float i) {
  ellipse(100, 100, i, i);
}

```

---

<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: [January 28, 2020, 11:01pm UTC](https://discourse.processing.org/t/how-can-i-run-a-for-loop-using-a-function/17403/5 "2020-01-28T23:01:40Z")

</div>

and welcome to the forum!

Great to have you here!
