Skip to content

Instantly share code, notes, and snippets.

@puckbag
Last active August 29, 2015 14:04
Show Gist options
  • Save puckbag/2acc0f2002b6bd96abce to your computer and use it in GitHub Desktop.
Save puckbag/2acc0f2002b6bd96abce to your computer and use it in GitHub Desktop.
How while and for loops function the same
// demonstrate how to construct the same loop with while and with for.
// a limited loop in while format
var limit = 10;
var i = 1;
while (i<=limit) {
console.log(i);
i = i + 1;
}
// exact same limited loop in for format
var limit = 10;
for (var i=1; i<=limit; i=i+1) {
console.log(i);
}
// demonstrate the most basic infinite loop with while and with for.
while (true) {
// over and over again.
}
for (;;) {
// over and over again.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment