Skip to content

Instantly share code, notes, and snippets.

@ryanw-mobile
Created March 7, 2023 03:31
Show Gist options
  • Save ryanw-mobile/d6c0594734263697a45fc3825c81f4a4 to your computer and use it in GitHub Desktop.
Save ryanw-mobile/d6c0594734263697a45fc3825c81f4a4 to your computer and use it in GitHub Desktop.
Kotlin for-loop: forEachIndexed
val bakes = listOf("sausage roll", "steak bake", "festive bake")
// Print each item in the list along with its index
bakes.forEachIndexed { index, bakeItem ->
println("$index: $bakeItem")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment