Completing a range-based loop in given code

Report a typo

Suppose you are given a piece of partially finished Kotlin code. The purpose of this code is to create a string that logs each iteration of a loop over a certain range, and then print that string. Your task is to fill the blanks in the code to complete the Kotlin range-based 'for' loop and ensure it works as expected. Don't forget to handle the range of iterations in the proper way.

Fill in the gaps with the relevant elements
fun main() {
    var result = ""
     (i  ) {
        result += "Loop iteration: $i\n"
    }
   (result)
}
printlnforin1..5

Create a free account to access the full topic