Skip to content

Instantly share code, notes, and snippets.

@slambert
Last active February 19, 2020 04:23
Show Gist options
  • Save slambert/405495b588fdda5bee81eec8d1cadbb4 to your computer and use it in GitHub Desktop.
Save slambert/405495b588fdda5bee81eec8d1cadbb4 to your computer and use it in GitHub Desktop.
/*
/ Steve Lambert February 18, 2020
/ Student Demo of Loops
/
*/
// global variables
color blue = #1f5673;
color aqua = #90c3c8;
color skyblue = #90c3c8;
color lavender = #b9b8d3;
void setup() {
size(500, 500);
smooth();
strokeWeight(5);
frameRate(1);
println("set up done");
} // end setup
void draw() {
background(lavender);
stroke(blue);
println("starting loops");
// This is a while loop
// start with i as 0
int i = 0;
// while i is less than the width of the window
while (i < width) {
println("while looping: " + i);
line(i, 20, random(width), 200);
i = i + 20;
}
// end of while loop
stroke(skyblue);
// This is a for loop
for (int b = 0; b < width; b += 20) {
println("for looping: " + b);
// create variable; when it should end; how to change var
line(b, 250, b, 450);
} // end for loop
println("end draw");
} // end draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment