fibonacci series js for loop code example
Example: fibonacci sequence in javascript using for loop
let fibonacci = [0, 1]; // set initial conditions
for (let i = 2; i < 10; ++i) {
// add the two previous elements to get the current element
fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
}
console.log(fibonacci); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]