[swift-users] For loop question?

Jacob Bandes-Storch jtbandes at gmail.com
Tue Dec 15 02:14:18 CST 2015


You can use `stride`:

for i in 0.stride(to: 10, by: 2) {
    print("i is \(i)")
}

On Tue, Dec 15, 2015 at 12:08 AM, Eirny Kwon via swift-users <
swift-users at swift.org> wrote:

> for loop is working
>
> for var i = 0; i < 10; i += 2 {
>
>     print("i is \(i)")
>
> }
>
>
> On December 15, 2015 at 5:05:41 PM, cooper liu via swift-users (
> swift-users at swift.org) wrote:
>
> Hi,
> If the c style for loop was removed,how to implement the following code
> beautifully:
> For(var i=0; i < 10; i+=2)
> Since the range operator ... doesn't support step other than 1, and it
> doesn't support end value < start value.
>
> Thanks!
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151215/5ca0552b/attachment.html>


More information about the swift-users mailing list