0 votes
78 views
asked in Swift by
Hi  

 How to handle loop very efficient in swift ?

2 Answers

0 votes
answered by

Hi

  We can acheive the loop using while alos

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

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
}

Categories

...