[swift-evolution] [Pitch] Retiring `where` from for-in loops

Brent Royal-Gordon brent at architechies.com
Wed Jun 8 22:36:37 CDT 2016


> Upon accepting SE-0099, the core team is removing `where` clauses from condition clauses, writing "the 'where' keyword can be retired from its purpose as a boolean condition introducer." 
> 
> Inspiried by Xiaodi Wu, I now propose removing `where` clauses from `for in` loops, where they are better expressed (and read) as guard conditions. 

Do you propose to remove `for case` as well? That can equally be handled by a `guard case` in the loop body.

Alternate proposal: Move `where` clauses to be adjacent to the pattern—rather than the sequence expression—in a `for` loop, just as they are in these other syntaxes.

	for n where n.isOdd in 1...1_000 { … }

This makes them more consistent with the syntax in `switch` cases and `catch` statements, while also IMHO clarifying the role of the `where` clause as a filter on the elements seen by the loop.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list