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.



int val = 30;
void draw() {
  int t = timestwo(val);

// The first 'int' in the function declaration
// specifies the type of data to be returned.
int timestwo(int dVal) {
  dVal = dVal * 2;
  return dVal;  // Returns an int of 60, in this case

int[] vals = {10, 20, 30}; 
void draw() { 
  int[] t = timestwo(vals); 
int[] timestwo(int[] dVals) { 
  for (int i = 0; i < dVals.length; i++) { 
    dVals[i] = dVals[i] * 2; 
  return dVals;  // Returns an array of 3 ints: 20, 40, 60 

void draw() {
  line(0, 0, width, height);
  if (mousePressed) {
    return;  // Break out of draw(), skipping the line statement below
  line(0, height, width, 0);  // Executed only if mouse is not pressed
Description Keyword used to indicate the value to return from a function. The value being returned must be the same datatype as defined in the function declaration. Functions declared with void can't return values and shouldn't include a return value.

The keyword return may also be used to break out of a function, thus not allowing the program to the remaining statements. (See the third example above.)
type function {
  return value
type boolean, byte, char, int, float, String, boolean[], byte[], char[], int[], float[], or String[]
function the function that is being defined
statements any valid statements
value must be the same datatype as the "type" parameter
Updated on September 22, 2016 07:39:38pm EDT

Creative Commons License