dart-lang / dart-lang/language

Allow collection `while`

Open
#3,093 3 comments 4 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

It's inconvenient to write `for (;cond;)` when you really mean `while(cond)` inside of collection.
I'd like to allow `while` to be used inside collection expansion, like that:
```dart
final objects = [
while (reader.remainingBytes > 0)
reader.readStruct(),
];
```
That would be just a syntax sugar for `for (;;)`, but without need of executing variables initialization and post-loop action.
`do`-`while` on the otherhand is useful, but probably would make syntax bit more complex and ambiguous (in collection `do` what?).

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the collection expansion syntax shown in the issue and comparing the proposed while form with the existing for (;;) form. Consider how the proposal relates to do-while syntax and whether the language specification can define it without ambiguity. Done means reaching and documenting a decision on the supported syntax and its semantics.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.