language icon indicating copy to clipboard operation
language copied to clipboard

Not accurate specification of `for` loop

Open sgrekhov opened this issue 2 years ago • 1 comments

Please see Dart specification 18.6.1. For loop

Execution of a for statement of the form for (var v = e; c; e) s proceeds as follows: If c is empty then let c be true otherwise let c' be c. First the variable declaration statement var v = e is executed.

Why only for (var v = e; ...) s form is mentioned? What about for (int v = e;...) or int i; for(i = 0; ...) forms? Or the following

  int i = -1;
  g() {i = 0;}
  for (g(); i < 2; i++) {
    print(i);
  }

Seems that this section should be rewritten.

Please also see https://github.com/dart-lang/sdk/issues/49495

sgrekhov avatar Jul 21 '22 08:07 sgrekhov

That is true, the for-loop section really needs a rewrite. Cf. https://github.com/dart-lang/language/issues/862 and https://github.com/dart-lang/language/issues/1951.

eernstg avatar Jul 26 '22 08:07 eernstg