Processing Intro #01 | Basic Grammar

Contents

Basic Grammar

Variables and Types

Declaration

Substitution

Conditional Branch

Array

Iteration

Animation

Practice – bouncing balls

variables

Initial Setup

Loop

Basic Grammar

Variables and Types

Programs are series of procedure to deal with bunch of variables. Variables are the main elements in computer programs and is sometimes compared to boxes to store data. Every variable have its data type. There are several several data types in python and other programming languages. Followings are popular variables in Processing:

boolean – True/False variables

int – Integer variables

float – floating-point arithmetic

String – Text variables

Declaration

To use variables, we need to declare variables first. You can declare variables like following:

<type name> <variable name> ( = <value> ) ;

int num;

Now you can make “num” as integer variable. Still, “num” is empty variable so you need to input a value in it to use. And “;” is something like “.” in natural languages. It indicates the end of the line.

Substitution

“=” is a relational operator that indicates right-hand side and left-hand side are equal in mathematics, but is a operator to substitute left-hand side for right-hand side in programming.

Therefore we can write a code following:

int a = 10;
a = a + 1;

As you can see above, you can declare variable and input data at once.

Conditional Branch

To branch processes in programming, use “if(…){…}else if(…){…}else{…}” syntax. There are several relational operators: