fun main() {
val numbers = listOf(1, 2, 3, 4, 5)
for (number in numbers) {
println("Current number: $number")
}
}
- Declare a function named
main
. - Create a constant
numbers
and assign it a list of integers (1, 2, 3, 4, 5). - Start a
for
loop to iterate over each element in the numbers
list. - Declare a variable
number
to represent the current element in the iteration. - Print the current number using
println
with the string "Current number: " followed by the value of the number
variable. - Repeat steps 4-5 for each element in the
numbers
list. - End the
for
loop. - End the
main
function.