2

3

4

5

8

Documentation - Donec ullamcorper nulla non metus auctor fringilla.

Download On Github

Structure

[ ] (array access)

datatypep[ ], array[element]

The array access operator is used to specify a location within an array. The data at this location can be defined with the syntax array[element] = value or read with the syntax value = array[element].

 
int[] numbers = new int[3]; 
numbers[0] = 90; 
numbers[1] = 150; 
numbers[2] = 30; 
	
// Sets variable a to 240 
int a = numbers[0] + numbers[1]; 
	
// Sets variable b to 180
int b = numbers[1] + numbers[2]; 

= (assign)

var = value

Assigns a value to a variable. The "=" sign does not mean "equals", but is used to place data within a variable. The "=" operator is formally called the assignment operator. There are many different types of variables (int, floats, strings, etc.) and the assignment operator can only assign values which are the same type as the variable it is assigning. For example, if the variable is of type int, the value must also be an int.

 
int a;
	
// Assigns the value 30 to the variable 'a'
a = 30; 
	
// Assigns the value 70 to the variable 'a'
a = a + 40;

catch

catch (exception)

The catch keyword is used with try to handle exceptions. Sun's Java documentation defines an exception as "an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions." This could be, for example, an error while a file is read.

 
BufferedReader reader;
String line;
	
void setup() {
	// Open the file from the createWriter() example
	reader = createReader("positions.txt");
}
	
void draw() {
	try {
		line = reader.readLine();
	} catch (IOException e) {
		e.printStackTrace();
		line = null;
	}
	
	if (line == null) {
		// Stop reading because of an error or file is empty
		noLoop();  
	} else {
		String[] pieces = split(line, TAB);
		int x = int(pieces[0]);
		int y = int(pieces[1]);
		point(x, y);
	}
}