Skip to content

Instantly share code, notes, and snippets.

@ethyde
Created September 30, 2014 15:15
Show Gist options
  • Save ethyde/7c3f03e99ce8309b9161 to your computer and use it in GitHub Desktop.
Save ethyde/7c3f03e99ce8309b9161 to your computer and use it in GitHub Desktop.
How to use javacript "for loop".
for(start value; condition; increment){
//code that will be executed over and over
}
// iterate 5 times use it for count loop
for(var i=0; i < 5; i++){
console.log("The value of i is: " + i + " <br />");
}
// increment by 2 instead of 1
for(var i=0; i < array.length; i += 2){
console.log(i + "<br />");
}
// reverse incremente order
for(var i=10; i < 0; i--){
console.log(i + "<br />");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment