xxxxxxxxxx
40
// notes form the coding train
// a repeat loop is a control structure
// a conditional statement is a control structure . the code runs once
// if the condition is true
// the control structure of a loop is written just like the if statements
// but wiht a different keyword besides if, while. while this boolean
//statement is true continue to do this code over and over and over
//again. watchout! its possible your program could get stuck inside
//the loop
//global variables: i can use them anywhere in my code
//local variable: a variable inside a function
// the while loop has 3 elements: the first one is we start with
//initializing a variable: var x =0;
//the second thing is we test for an exit condition: x<=width
// the third thing is we have this incrementation operation x= x+50
// those 3 elements are so common in loops that there is an entire
//other looping structure called a for loop that condenses the elemntss
//x = x+50 is so common it can be written in shorthand as x+=50
//x = x+1 shorthand is x++
function setup() {
createCanvas(600, 400);
}
function draw() {
var x = 0;
background(0);
strokeWeight(4);
stroke(255);
while (x <= width) {
fill( 0,200,255);
ellipse(x, 100, 25, 25);
x = x + 50;
}
for (var x = 0; x<=width; x=x+50) {
fill( 155,200,0);
ellipse(x,300,25,25);
}
}