Repeat and Its Usage in Kotlin


Definition

Repeat statement is like while loop, which executes a block of code  N-number of times (without any condition).

Syntax

repeat(N) {
   Code to execute N Number of Times
} 

Repeat Loop Example Program in Kotlin


// Repeat Loop in Kotlin example program
// Loop and Control Statements Kotlin Programs, Basic Kotlin Programs

fun main(args: Array<String>) {
    
    repeat(5) {
       println("Printing Repeat Statement")
    }
    
}

Sample Output

Printing Repeat Statement
Printing Repeat Statement
Printing Repeat Statement
Printing Repeat Statement
Printing Repeat Statement