let n = 5;
for (let a = 1, b = Math.pow(2, a); b <= n; a++) {
console.log(b);
}
I don’t understand why b doesn’t increase as a increases. Do I have to somehow pass a to b again?
If there’s no way to make this loop work this way, can someone tell me how I could rewrite it so it works?
>Solution :
Once b is initialized, your code never changes it, so the loop condition is always true.
You could use
let n = 5;
for (b = 2; b <= n; b*=2) {
console.log(b);
}