Declaring Variables
In order for a Processing program to be useful we need to be table to store information and be able to change it as necessary. We do this my using variables. When the program is executed, the variable declaration sets aside the memory necessary to store the information required.
Variable Rules
To use variables, there are a number of rules that must be followed.
<data type> <identifier name> = <initial value>;
To use variables, there are a number of rules that must be followed.
- A variable must be declared before we can use it in the program.
- The program must identify the data type of the variable. That is, we have to tell the computer the kind of information we are going to store in the variable.
- To use the variable in a program we have to give it a name. In computer science, we call it an identifier.
- In Processing, we must give a variable an initial value
- The statement is ended with a semicolon;
<data type> <identifier name> = <initial value>;
Primitive Data Types
The most common data types that we will use are described in the table below
The most common data types that we will use are described in the table below
As a programmer, we control the data within our program. Integers can be categorized using the following data types. The most common is the int data type
Try entering this into Processing. What happened?
Now, add the missing line of code...
Now, add the missing line of code...
Now your code will run.
Change the value in line 2 to any integer and rerun the code.
Change the value in line 2 to any integer and rerun the code.