-5

How we can differentiate for loop and for each loop in swift language ?

Bucket
  • 449
  • 3
  • 20

2 Answers2

2

do like

for i in 0..<100 {
print("Number \(i)")
}

for more sample, you can get here

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
2

If you want to do it with some step, just use it (step is 2):

for i in stride(from: 0, to: 100, by: 2) {
    print(i)
}
Vlad Khambir
  • 4,313
  • 1
  • 17
  • 25