-1

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

saados
  • 17
  • 4
  • I found that continue is just disallowed as a correct code since it is unreadable. Sorry for the inconvient – saados Apr 27 '23 at 12:21
  • It's nothing about `async`/`await`, it's just that [that ESLint rule disallows using `continue`, at all](https://eslint.org/docs/latest/rules/no-continue#rule-details). If you want to use `continue`, you need to turn off the rule (or at least disable it for that line). – T.J. Crowder Apr 27 '23 at 12:21
  • 1
    *"*I found that continue is just disallowed as a correct code since it is unreadable.*" FWIW, that's a matter of opinion. Another opinion is that there's a good reason this rule isn't in the default set. ;-) – T.J. Crowder Apr 27 '23 at 12:23

2 Answers2

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>
      }     
}
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
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.

AngYC
  • 3,051
  • 6
  • 20