26 september 2009

Lesson 2

Stuff we lately did

So we did a lot of things. In short, I discussed data types, for-loops and functions. Defining a datatype for you variable is important. The computer is not that intelligent, you have to tell it whether your variable contains an integer, float, boolean value, etc.
int p = 12;
float q = 12.5;
boolean r = true;
You'll have errors concerning the mistake of forgetting the datatype often. Don't mind, in the end it'll help you be more precise.

For-loops

You'll use for-loops for repetitions. If you want to draw 100 ellipses, you're not going to write them line by line. You will grab a for-loop. For example:
for (int i = 0; i < 100; i++) {
  ellipse(i,i,10,10);
}
The statement says this:
  • in our initial state, i = 0.
  • the for-loop will repeat itself as long as i is smaller than 100.
  • after every loop, i will be added with 1.
int i = 0;
// the following three statements are identical.
// They all add 1 to i.
i = i + 1;
i += 1;
i++;

Geen opmerkingen:

Een reactie posten