skip to Main Content

I have the following code:

for await (const ele of offCycles) {
      if ((await MlQueueModel.find({ uuid: ele.uuid })).length !== 0) {
        continue;
      }
     <do something>
}

Is it possible to use a continue inside a for await loop ?
I received the following error:
Unexpected use of continue statement.eslintno-continue

I would like to continue the loop when the condition is true

2

Answers


  1. The error is just a coding style issue instead of an actual error in JavaScript. Some argues that using continue statement is a bad practise but generally it is quite opinionated.

    You can disable the rule by adding "no-continue": "off" in your eslint config so that you can use it. Read more about the use of this rule here: https://eslint.org/docs/latest/rules/no-continue

    I have found this interesting question here that will explain to you about the use of continue / break: https://softwareengineering.stackexchange.com/questions/434124/are-there-any-problems-with-using-continue-or-break

    Basically, if you know what you are doing, then it is not an issue.

    Login or Signup to reply.
  2. That’s an eslint error, not a JavaScript error.

    You can:

    for await (const ele of offCycles) {
          if ((await MlQueueModel.find({ uuid: ele.uuid })).length === 0) {
                <do something>
          }     
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search