The for loop with an array

Using the for loop to iterate through an array of values can be done as follows:

var animals = arrayOf("Cat", "Lion");

...
for (index in animals.indices) {
println("This is a great animal : ${animals[index]}")
}

Here, the animals array has an indices property that itself is an array of Int, which can be used to loop through each index and print the value of that index. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.14.93