Created
March 31, 2017 10:23
-
-
Save igorshubovych/585a7bc383dda47ced22bf03e072fff0 to your computer and use it in GitHub Desktop.
JavaScript loops
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
// Factorial | |
// n | |
// 1 * 2 * 3 * ... * (n-1) * n | |
const n = 7; | |
let fact = 1; | |
for (let i = 1; i <= n; i++) { | |
fact = fact * i; | |
console.log('i=', i); | |
console.log('fact=', fact); | |
console.log('------------') | |
} | |
let i = 1; | |
fact = 1; | |
while (i <= n) { | |
fact = fact * i; | |
console.log('i=', i); | |
console.log('fact=', fact); | |
console.log('------------'); | |
i++; | |
} | |
i = 1; | |
fact = 1; | |
do { | |
fact = fact * i; | |
i++; | |
console.log('i=', i); | |
console.log('fact=', fact); | |
console.log('------------'); | |
} while (i <= n); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment