While loop is not working in processing

I am beginner in processing, just started few days ago. I am learning while loop now but when i run the program, while loop does not seem to be working. I tried so much but still don’t know what problem is occuring

float circleX = 320;
float circleY = 50;
float speed = 1;
void setup()
{
  size(640,360);
}

void draw(){
  background(50);
  while(circleY < height)
  {
    circle(circleX, circleY, 10);
    circleY += speed;
    speed += 0.3;
  }
}

@nothingelse
Please post your code so we can see where the issue is…

I posted my code now, please tell me the solution

It looks like you’re trying to move a circle until it hits the bottom of the window. While the circle isn’t at the bottom yet, you want to move it down, and it speeds up.

The problem is that you don’t need a while loop to do this! Confusing, right? You already have a loop, and that loop is draw() being called over and over. Consider these changes:

float circleX = 320;
float circleY = 50;
float speed = 1;
void setup() {
  size(640,360);
}

void draw(){
  background(50);

  if (circleY < height) {
    circleY += speed;
    speed += 0.3;
  }

  ellipse(circleX, circleY, 10, 10);
}

Also note that the function to draw a circle is actually ellipse().

so what does circle function is mode for mainly?

Thanks but if i want to use while loop later in future so what will i do at that time?

For introductory guidance, this type of question can be answered by reading the Processing reference, linked below:

https://processing.org/reference/

And there are several tutorials on YouTube. You could start here:

And here:

Good luck! :slight_smile:

1 Like

For a quicker clarification, refer to the reference for this type of question. About the circle() can be found here:

https://processing.org/reference/circle_.html

I am learning processing from coding train channel which mention in the first video.