"#warning: c-style for statement is deprecated and will be removed in a future version of swift " Code Answer

1

removing for init; comparison; increment {} and also remove ++ and -- easily. and use swift's pretty for-in loop

   // warning: c-style for statement is deprecated and will be removed in a future version of swift
   for var i = 1; i <= 10; i += 1 {
      print("i'm number (i)")
   }

swift 2.2:

   // new swift style works well
   for i in 1...10 {
      print("i'm number (i)")
   }  

for decrement index

  for index in 10.stride(to: 0, by: -1) {
      print(index)
  }

or you can use reverse() like

  for index in (0 ..< 10).reverse() { ... }

for float type (there is no need to define any types to index)

 for index in 0.stride(to: 0.6, by: 0.1) {
     print(index)  //0.0 ,0.1, 0.2,0.3,0.4,0.5
 }  

swift 3.0:

from swift3.0, the stride(to:by:) method on strideable has been replaced with a free function, stride(from:to:by:)

for i in stride(from: 0, to: 10, by: 1){
    print(i)
}

for decrement index in swift 3.0, you can use reversed()

for i in (0 ..< 5).reversed() {
    print(i) // 4,3,2,1,0
}


other then for each and stride(), you can use while loops

var i = 0
while i < 10 {
    i += 1
    print(i)
}

repeat-while loop:

var a = 0
repeat {
   a += 1
   print(a)
} while a < 10

check out control flows in the swift programming language guide

By rgrebski on February 11 2022

Answers related to “#warning: c-style for statement is deprecated and will be removed in a future version of swift ”

Only authorized users can answer the Search term. Please sign in first, or register a free account.