Posts

Purpose of repeat function

Image
3 0 Using kotlin I can repeat an action in at least two ways: val times = 5 // First option for (i in 0 until times) { print("Action $i") } // Second option repeat(times) { print("Action $it") } I'd like to know the purpose of repeat . Should the traditional for loop be replaced with repeat function if possible? Or are there special cases for this function? Are there any advantages in repeat function? EDIT I've made some research about this question. As long as kotlin is open source project, I could download the sources and check git history. I found that 1) repeat function is a replace for times function extension. public inline fun Int.times(body : () -> Unit) 2) KT-7074. times function has become deprecated. But why? ...