The review of SE-0007 “Remove C-style for-loops with conditions and incrementers” ran from December 7–10, 2015. The proposal has been accepted for Swift 3.0.
Thank you to everyone who participated in the review process! We had a lot of discussion around this proposal. For the most part, there was agreement that C-style for loops are quite rare in Swift code, and most of the existing uses would be better written as for-in loops. Much of the debate focused on two particular areas where the removal of C-style for loops could cause problems:
* Some loops are awkward to express cleanly with for-in, such as counting down, and there are advanced uses of C-style for loops that are hard to express otherwise. The core team feels that some of the awkwardness for simple loops (e.g., counting down) should be addressed by improvements in the Standard Library, and that the remaining, more advanced uses are not common enough to justify keeping C-style for loops in the language.
* Performance of the for-in loop lags behind that of the C-style for loop in some cases. The core team feels that optimizer improvements can close this performance gap, and that ‘while’ loops are an acceptable substitute for performance-critical code where the optimizer isn’t yet eliminating the abstractions used in the for-in loop.
We welcome implementations of this proposal! Because it involves the removal of an existing feature, the implementation will need to be staged across the two upcoming Swift releases:
* For Swift 2.2: introduce a warning to tell users that the C-style for loop is going away (covered by https://bugs.swift.org/browse/SR-226)
* For Swift 3.0 (once we branch 2.2): actually remove C-style for loops (covered by https://bugs.swift.org/browse/SR-227)
For reference, the proposal document is here:
- Doug Gregor, Review Manager