Kotlin repeat statement is used when a set of statements has to be executed N-number of times.

Example 1 – Kotlin repeat()

In this example, we will use a repeat statement to execute print statement 4 times.

Kotlin Program – example.kt

fun main(args: Array) {
    repeat(4) {
        println("Hello World!")
    }
}
ADVERTISEMENT

Output

Hello World!
Hello World!
Hello World!
Hello World!

You can have any number of statements inside repeat block.

Conclusion

In this Kotlin Tutorial, we learned how to use repeat statement to repeat the execution of a block of statements for specific number of times.