dart-lang / dart-lang/language
Use block-scoped variables in `while`
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Currently this does not work:
```dart
void main() {
do {
int n = 1;
} while (n > 1); // Error: Undefined name 'n'.
}
```
This is because the scope of `n` ends with `}`
However, this does not mirror the way that `for` works. `for` creates a scope that end with `}` despite that the variable is defined outside of `{}`:
```dart
void main() {
for (int n in [1]) {}
n = 2; // Error: Setter not found: 'n'.
}
```
If this suggestion is implemented, conditional loops can be made easier.
Contributor guide
Research direction
The issue names no file, test, or entry point. Start by comparing the specified scoping rules for do-while and for loops; done means the requested behavior is resolved consistently with the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100