Skip to content

Instantly share code, notes, and snippets.

@slambert
Created September 20, 2016 21:55
Show Gist options
  • Save slambert/75ee8fc14e5b613c283e582ba8f830c9 to your computer and use it in GitHub Desktop.
Save slambert/75ee8fc14e5b613c283e582ba8f830c9 to your computer and use it in GitHub Desktop.
for vs while with same result
//Steve Lambert September 20, 2016
//for and while loop demo v1
void setup() {
size(500,500);
smooth();
} // end setup
void draw() {
background(255);
// 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 ){
line(i,20,i,200);
//i++;
i = i + 10;
}
// This is a for loop
for(i = 0; i < width; i += 10){
line(i,250,i,450);
} // end for loop
} // end draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment