Hi, i’m quite new to coding in general and having a really hard time with this. Currently my loop is running from 0-1000 in a single click, but i need it to break out of the loop when i let go of the mouse. I’m guessing my If to trigger the break is placed incorrectly, but i don’t understand why isPressed isn’t being checked every time the loop executes.
Here’s a simplified sketch of the problem:
var isPressed = false; 
function setup() {
createCanvas(1000, 500);
  background(0);
}
function draw() {
  test();
}
function test()
{
  if (mouseX>0 && mouseX<width && mouseY<height && mouseY>0 && isPressed === true)
  {
      testLoop:
      for (var i=0; i<1000; i++)
      {
        if (isPressed === false)
        {
          break testLoop;
        }
        else 
        {
          print("push");
        }
      
      }   
  }
}
function mousePressed()
  {
    isPressed = true;
  }
  
function mouseReleased()
  {
    isPressed = false;
  }
Here’s my actual code:
//--------------------------------------------
//DRAWS BEATERS ON-SCREEN
function BeaterControl()
{
  
  if (mouseX>0 && mouseX<width && mouseY<height && mouseY>0 && isPressed === true)
  {
      arrayLoop:
      for (var beaterID=0; beaterID<1000; beaterID++)
      {
        if (isPressed === false)
        {
          break arrayLoop;
        }
        else 
        {
          beaterArray[beaterID] = beaterArray.push(new Beater());
        }
      
        console.log(beaterArray[10]);
        //console.log(beaterArray[beaterID].y);
      }
        
      if (beaterSize <= 20)
      {
          beaterSize = (beaterSize+0.2);
      }
       
  }
      
  if (isPressed === false)
  {
    beaterSize = 0;
  }
 
    
}
function Beater()
{
  this.x = mouseX;
  this.y = mouseY;
  this.diameter = beaterSize;
  
  this.beaterFill = fill(250,250,0,250);
  this.beaterDisplay = ellipse(this.x,this.y,10,10);
}
            