kotlin repeat n times
Certainly! Here is a response:
fun main() {
val n = 5
repeat(n) {
println("Hello, world!")
}
}
Explanation:
1. Declares a main function using the fun
keyword.
2. Initializes a variable n
with the value 5.
3. Calls the repeat
function with n
as the argument.
4. The repeat
function executes the specified block of code (in this case, println("Hello, world!")
) n
times.