let index = 10;
let jump = 2;
for (;;) {
// Write Your Code Here
let i = index;
console.log(i);
i -= jump;
if (i === jump) {
break;
}
}
I think that I know the logic of the code, but I don’t understand why it does loop infinitely
>Solution :
maybe the following code fixes the problem.
let index = 10;
let jump = 2;
let i = index;
for (;;) {
// Write Your Code Here
console.log(i);
i -= jump;
if (i === jump) {
break;
console.log('broken...')
}
}
The reason is variable i is being refreshed with static index value 10 every time it loops. Hence it never breaks.