Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do something when a for loop ends

I have a for loop in JavaScript, and I want some code to run when it ends. This works, but I'm wondering if there are any simpler solutions:

for (var i = 1; i <= 100; i++) {
    console.log('Line ' + i);

    if (i === 100) {
        alert('Loop ended!');
    }
}

1 Answers

for (var i = 1; i <= 100; i++) {
    console.log('Line ' + i);
}

alert('Loop ended!');
like image 63
Chetan Avatar answered Jun 15 '26 00:06

Chetan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!