This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

else

Examples
example pic
for (int i = 5; i < 95; i += 5) {
  if (i < 35) {
    line(30, i, 80, i);
  } else {
    line(20, i, 90, i);
  }
}
example pic
for (int i = 5; i < 95; i += 5) {
  if (i < 35) {
    line(30, i, 80, i);
  } else if (i < 65) {
    line(20, i, 90, i);
  } else {
    line(0, i, 100, i);
  }
}
Description Extends the if structure allowing the program to choose between two or more blocks of code. It specifies a block of code to execute when the expression in if is false.
Syntax
if (expression) { 
  statements 
} else { 
  statements 
} 

if (expression) { 
  statements 
} else if (expression) { 
  statements 
} else { 
  statements 
}
Parameters
expression any valid expression that evaluates to true or false
statements one or more statements to be executed
Relatedif
Updated on January 1, 2021 03:38:12am EST