The array and for loop

The for loop is used with all collection types, and arrays are no exception. We can access every element of the array using the for loop.

Take a look at the following example:

fun arrayAndForloop(){
val strArray = arrayOf("ONE","TWO","THREE","FOUR","FIVE")
for (element in strArray){
println(element)
}
}

On each iteration, the for loop fetches a value from strArray and assigns it to the element. We can use this value in the body of the loop.

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

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