Mobile App Development - Kotlin

Back to Course

Lesson Description

Lession - #399 Kotlin For

Frequently when you work with arrays, you want to loop through the all of the elements.

To loop through array elements, utilize the kotlin for loop with the "in" operator.

Let's see an example

fun main(>
{ val flowers = arrayOf("rose", "lily", "lotus">
for (x in flowers>
{ println(x>
} }


Try it here

How do you find the for loop with index?
You can access the index even without using enumerate(>
1.Using a for loop, iterate through the length of my_list .
2. Loop variable index starts from 0 in this case.
3. In each iteration, get the value of the list at the current index using the statement value = my_list[index] .
4. Print the value and index .

How do you break a forEach in Kotlin? 'break' and 'continue' in forEach in Kotlin
Break - This is a keyword that helps in terminating an iteration, once a given condition is met, while traversing through a collection.
Continue - This keyword helps to continue the iteration once a condition is fulfilled.

kotlin switch case : Kotlin jobs :

Kotlin not configutred android :