Name

while

Description

Controls a sequence of repetitions. The while structure executes a series of statements continuously while the expression is true. The expression must be updated during the repetitions or the program will never "break out" of while.

This function can be dangerous because the code inside the while loop will not finish until the expression inside while becomes false. It will lock out all other code from running (e.g., mouse and keyboard events will not be updated). Be careful — if used incorrectly, this can lock up your code (and sometimes even the Processing environment itself).

Examples

  • size(400, 400);
    int i = 0;
    while (i < 320) {
      line(120, i, 320, i);
      i = i + 20;
    }
    Image output for example 1

Syntax

  • while (expression) {
  • statements
  • }

Parameters

  • expressiona valid expression
  • statementsone or more statements

Related