Professional Documents
Culture Documents
Loops
Initialize
Executes once when loop begins
Evaluation
loop will be executed if test evaluates to true
Update
is executed at the end of each iteration
false
for (int i = 0; i < 100; i++) {
Iterations
true
i++
Console output
iteration: 0
iteration: 1
println(iteration: + i);
iteration: 2
[...]
iteration: 99
continue code
Introduction 3
Functions
Name
function Name, lowercase
void drawCircle() {
continue code
Introduction 3
Parameter list
declaration of variables separated by comma
// draw circles
for (int i = 100; i < 800; i+=100) {
drawCircle (i, i);
}
continue code
Introduction 3
Parameter list
declaration of variables separated by comma
// draw circles
int radius;
for (int i = 100; i < 800; i+=100) {
radius = drawCircle (i, i);
println (Circle + i + - radius + radius);
}
Circle 1 - radius 15
Circle 2 - radius 23
Circle 3 - radius 76
[...]
Introduction 3
Variable
Scope
global variabels
are defined at the beginning
of the code, outside any curly
brackets
are accessible anywhere
local variabels
void setup () {
size (800,600);
smooth();
noFill();
maxRadius = 300;
for (int i = 0; i < number; i++) {
int posX = int(random(width));
int posY = int(random(height));
drawCircle(posX, posY);
println (iteration + i);
}
}
println (i);
println (rad);
println (x);
println (maxRadius);