loop()

Examples

void setup() {
  frameRate(10);
  noLoop();  // draw() will not loop
}

float x = 0;

void draw() {
  background(255);
  x = x + 1;
  if (x > sketchWidth) {
    x = 0;
  }
  line(x, 0, x, sketchHeight); 
}

// For use these functions, define ENABLE_KEY_EVENT in settings.h
void keyPressed() {
  loop();  // Holding down a button activates looping
}

void keyReleased() {
  noLoop();  // Releasing a button stops looping draw()

Description

By default, Processing loops through draw() continuously, executing the code within it. However, the draw() loop may be stopped by calling noLoop(). In that case, the draw() loop can be resumed with loop().

Syntax

loop()

Returns

void

Related

noLoop()
redraw()

Back to index