Why are “continue” statements bad in JavaScript? [closed]

The statement is ridiculous. continue can be abused, but it often helps readability.

Typical use:

for (somecondition)
{
    if (!firsttest) continue;
    
    some_provisional_work_that_is_almost_always_needed();

    if (!further_tests()) continue;

    do_expensive_operation();
}

The goal is to avoid ‘lasagna’ code, where you have deeply nested conditionals.

Edited to add:

Yes, this is ultimately subjective. Here’s my metric for deciding.

Edited one last time:

This example is too simple, of course, and you can always replace nested conditionals with function calls. But then you may have to pass data into the nested functions by reference, which can create refactoring problems at least as bad as the ones you’re trying to avoid.

Leave a Comment