While loops ought to support the same syntax as conditionals for assigning the result of an expression to a value scoped to that loop.
void main(){
if(auto value = 1){} // compiles
while(auto value = 1){} // expression expected, not 'auto'
}
Comment #1 by ketmar — 2016-06-09T07:01:02Z
*** This issue has been marked as a duplicate of issue 13526 ***
Comment #2 by ketmar — 2016-06-09T07:01:39Z
oops. sorry, i misread "with" as "while"... ;-)
Comment #3 by deadalnix — 2021-03-01T15:19:45Z
+1 This shouldn't be too difficult to fix and would make some code much nicer.
Comment #4 by dlang-bot — 2021-03-02T16:23:27Z
@RazvanN7 created dlang/dmd pull request #12246 "Fix Issue 16140 - while(auto x = y) does not behave like if(auto x = y)" fixing this issue:
- Fix Issue 16140 - while(auto x = y) does not behave like if(auto x = y)
https://github.com/dlang/dmd/pull/12246
dlang/dmd pull request #12246 "Fix Issue 16140 - while(auto x = y) does not behave like if(auto x = y)" was merged into master:
- 43aa3eeecefb08e1ea5496e12eb9e1feffc54c89 by RazvanN7:
Fix Issue 16140 - while(auto x = y) does not behave like if(auto x = y)
https://github.com/dlang/dmd/pull/12246
Comment #8 by razvan.nitu1305 — 2021-04-09T06:59:09Z
*** Issue 21811 has been marked as a duplicate of this issue. ***