[swift-evolution] Add a while clause to for loops
Tim Vermeulen
tvermeulen at me.com
Tue Jun 7 17:16:47 CDT 2016
I think `when` would be pretty confusing. If I didn’t know what it meant and I had to guess, I’d probably think that it means what `where` currently means.
Calling it `while` could perhaps cause confusing with the while loop, but it means the same thing in both contexts so people might already feel familiar with it.
> > On Jun 7, 2016, at 1:16 PM, Tim Vermeulen via swift-evolution<swift-evolution at swift.org(mailto:swift-evolution at swift.org)>wrote:
> > > The meaning of the proposed while is not at all a pair for where, since where clauses in while loops would do the same thing as while clauses in for loops. That's crazy.
> >
> > It sounds crazy, but it’s the nature of the while loop. A where clause in a while loop also has a different result than a where clause in a for loop.
> The where_clause appears in the for in statement
>
> for_in_statement : 'for' 'case'? pattern 'in' expression where_clause? code_block
>
> It's syntactic sugar because the expression can be already be limited through functional chaining of some sort or another. At the same time, it's nice and pleasant to have `where` and I'm not itching to throw it out. The same courtesy could be easily extend to `when` (because I don't really want to use the `while` keyword here, but I could easily be convinced otherwise because I don't have a strong stance either way):
>
> for_in_statement : 'for' 'case'? pattern 'in' expression (where_clause | when_clause)? code_block
> when_clause : 'when' expression
>
> and again it could be nice and pleasant to have, although not necessary. The question comes down to how much does the language benefit by this sugar.
>
> I'd say that in both cases, combining chaining and statements is marginallyless goodthan either using standalone chaining or statements without chaining. But as I say this, I know as a fact, I fully intend to use `sequence(_:, next:).take(while:)` with for0in statements, so I'm starting from a hypocritical vantage point.
>
> To summarize, I'm more +0.01 than I am -0.01 on this.
>
> -- E
> p.s. Sorry, wux
>
>
>
>
>
More information about the swift-evolution
mailing list