diff --git a/libraries/stdlib/samples/test/samples/misc/controlFlow.kt b/libraries/stdlib/samples/test/samples/misc/controlFlow.kt new file mode 100644 index 00000000000..8935e8a728b --- /dev/null +++ b/libraries/stdlib/samples/test/samples/misc/controlFlow.kt @@ -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!") + } + } +} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index da34bc0eb01..aa3acb3c8b5 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -128,6 +128,8 @@ public inline fun T.takeUnless(predicate: (T) -> Boolean): T? { * Executes the given function [action] specified number of [times]. * * A zero-based index of current iteration is passed as a parameter to [action]. + * + * @sample samples.misc.ControlFlow.repeat */ @kotlin.internal.InlineOnly public inline fun repeat(times: Int, action: (Int) -> Unit) {