mjs icon indicating copy to clipboard operation
mjs copied to clipboard

for loop is failing if any of the statements are omitted

Open Dietatko opened this issue 6 years ago • 0 comments

The for loop parsing fails if any of the statements is missing. Each of these fail to parse:

let i = 0;
for (; i < 1; i++) {
   // Do something
}
for (i = 0; ; i++) {
   if (i == 1)
      break;
}
for (i = 0; i < 1; ) {
   i++
}

The JavaScript allows any of those to be omitted. While the 2nd and 3rd statement is rarely omitted, it is not that rare the 1st statement is omitted. The workaround is:

let i = 0;
for (i = i; i < 1; i++) {
   // Do something
}

Dietatko avatar Sep 06 '19 13:09 Dietatko