Add sample for 'repeat' function
Co-authored-by: Ilya Gorbunov <ilya.gorbunov@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package samples.misc
|
||||||
|
|
||||||
|
import samples.*
|
||||||
|
|
||||||
|
class ControlFlow {
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun repeat() {
|
||||||
|
// greets three times
|
||||||
|
repeat(3) {
|
||||||
|
println("Hello")
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(0) {
|
||||||
|
error("We should not get here!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,6 +128,8 @@ public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
|
|||||||
* Executes the given function [action] specified number of [times].
|
* Executes the given function [action] specified number of [times].
|
||||||
*
|
*
|
||||||
* A zero-based index of current iteration is passed as a parameter to [action].
|
* A zero-based index of current iteration is passed as a parameter to [action].
|
||||||
|
*
|
||||||
|
* @sample samples.misc.ControlFlow.repeat
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user