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 {//w  w  w .jav  a2s  .co m
   print("*")  //prints out ****
}

Result

The preceding code outputs the asterisk five times.

Related Topic