[swift-evolution] Review for: Remove C-style for-loops with conditions and incrementers
Matthew Johnson
matthew at anandabits.com
Sat Dec 12 13:28:04 CST 2015
> Offhand (can't test right now) I suppose that means there's no use in
> adding `repeat` (or, `loop`, or whatever) to `for ... in`?
It could simplify for … in loops where there are early continue statements if there is also some logic that needs to be executed following *every* iteration, including those exited by a continue statement. I’m not sure how common examples of this would be but they probably exist. Where such logic exists the ‘repeat’ / ‘loop’ / etc construct would simplify it and make it less prone to error especially over time as maintenance is performed on the code.
If we introduce a construct like this we could also introduce a companion ‘between’ (keyword doesn’t really matter) which *would* do exactly what you intended.
for item in sequence {
print("\(item)")
} between {
print(", ")
}
More information about the swift-evolution
mailing list