Swift - For in loop range

Introduction

To perform an action a fixed number of times and don't care about the number of each iteration, specify an underscore _ in place of a constant:

Demo

//print * 5 times
for _ in 1...5 {/*ww w . ja va 2  s  .c o m*/
   print("*")  //prints out ****
}

Result

The preceding code outputs the asterisk five times.

Related Topic