How to handle loop very efficient in swift ?

0 votes
24 views
asked May 10 in Swift by anonymous
Hi  

 How to handle loop very efficient in swift ?

2 Answers

0 votes
answered May 11 by anonymous

Hi

  We can acheive the loop using while alos

var g = a.generate()
while let x = g.next() {
    sum += x
}
0 votes
answered May 11 by anonymous

HI 

  Classic way to write the loop

  var sum = 0
  for var i = 0; i < a.count; ++i {
     sum += a[i]
  }

For... in

for x in a {
    sum += x
}
...