2
for(i=2;i<=num/2;i++){

}

How to write this loop in swift3 without using while loop and repeat while loop?

I want to use only for loop for this.But right now Swift3 remove the old c styling loop. enter image description here

akshay
  • 765
  • 6
  • 20
  • Possible duplicate of [The ++ and -- operators have been deprecated Xcode 7.3](http://stackoverflow.com/questions/35158422/the-and-operators-have-been-deprecated-xcode-7-3) – vadian Dec 13 '16 at 08:18
  • My question is not duplicate.In your link they are using half (..<) and full (…) ranges .They cannot be fit into my requirement. @Pragnesh solved my problem. Thanks for your reply – akshay Dec 13 '16 at 09:44
  • The `stride` solution is also mentioned in the linked topic. – vadian Dec 13 '16 at 09:47
  • Yes @Vadian ... My mistake . I missed that part. Thanks for your help. – akshay Dec 13 '16 at 09:52

1 Answers1

2

You should write this:

for i in stride(from: 2, through: num/2, by: 1)
    {
        print(i)
    }
Pragnesh Vitthani
  • 2,532
  • 20
  • 28