Skip to content

Commit

Permalink
test(samples): add new samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kotlin-samples-pusher-bot committed Nov 27, 2024
1 parent a9edcca commit 79b9491
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//sampleStart
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return // non-local return directly to the caller of foo()
listOf(1, 2, 3, 4, 5).forEach lit@{
if (it == 3) return@lit // local return to the caller of the lambda - the forEach loop
print(it)
}
println("this point is unreachable")
print(" done with explicit label")
}
//sampleEnd

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//sampleStart
fun foo() {
listOf(1, 2, 3, 4, 5).forEach lit@{
if (it == 3) return@lit // local return to the caller of the lambda - the forEach loop
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return@forEach // local return to the caller of the lambda - the forEach loop
print(it)
}
print(" done with explicit label")
print(" done with implicit label")
}
//sampleEnd

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//sampleStart
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return@forEach // local return to the caller of the lambda - the forEach loop
print(it)
}
print(" done with implicit label")
listOf(1, 2, 3, 4, 5).forEach(fun(value: Int) {
if (value == 3) return // local return to the caller of the anonymous function - the forEach loop
print(value)
})
print(" done with anonymous function")
}
//sampleEnd

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//sampleStart
fun foo() {
listOf(1, 2, 3, 4, 5).forEach(fun(value: Int) {
if (value == 3) return // local return to the caller of the anonymous function - the forEach loop
print(value)
})
print(" done with anonymous function")
run loop@{
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return@loop // non-local return from the lambda passed to run
print(it)
}
}
print(" done with nested loop")
}
//sampleEnd

Expand Down

This file was deleted.

0 comments on commit 79b9491

Please sign in to comment.