dart-lang / dart-lang/language

Not accurate specification of `for` loop

Open
#2,353 1 comment 0 reactions 0 assignees View on GitHub
bug specification
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Please see Dart [specification](https://spec.dart.dev/DartLangSpecDraft.pdf) 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
```dart
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

Contributor guide

Open the contributing guide

Research direction

Start by reading section 18.6.1 of the linked Dart specification and compare its wording with the loop forms and example in this issue. Review the related SDK issue 49495 for context; done means the specification accurately describes the declaration, assignment, and expression forms of for loops.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.