Skip to content

Instantly share code, notes, and snippets.

@mathieu-anderson
Last active March 2, 2019 09:52
Show Gist options
  • Save mathieu-anderson/568b144082bd1547df019de867f04953 to your computer and use it in GitHub Desktop.
Save mathieu-anderson/568b144082bd1547df019de867f04953 to your computer and use it in GitHub Desktop.
Explaining the loop syntax to a friend
for (var i = 0; i < 9; i++) {
// var i = 0; -> initial value of the loop statement : i === 0
// executed before the first iteration
// i < 9 -> condition that must be true for the loop to proceed : check if i is less than 9
// if it is not less than 9, end the loop
// if it is less than 9, do the thing inside the loop :
console.log('The current value of i is :', i)
// i++ -> post statement (executed at the end of an iteration) : increment i by 1 (i++ is the same as i + 1)
}
// Expected result :
// The current value of i is : 0
// The current value of i is : 1
// The current value of i is : 2
// The current value of i is : 3
// The current value of i is : 4
// The current value of i is : 5
// The current value of i is : 6
// The current value of i is : 7
// The current value of i is : 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment