Last active
August 29, 2015 14:04
-
-
Save puckbag/2acc0f2002b6bd96abce to your computer and use it in GitHub Desktop.
How while and for loops function the same
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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