How can I run a for loop using a function?

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

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.

1 Like

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/

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

1 Like

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

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?

1 Like



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);
}
1 Like

and welcome to the forum!

Great to have you here!