Skip to content

Commit 9eb81e7

Browse files
author
Hai Nguyen
committed
change example
1 parent 2c6a3a6 commit 9eb81e7

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎core-kotlin/src/test/kotlin/com/baeldung/kotlin/StructuralJumpTest.kt‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class StructuralJumpTest {
99
@Test
1010
fun givenLoop_whenBreak_thenComplete() {
1111
var value = ""
12-
for (i in 'a'..'e') {
13-
value += i.toString()
14-
if (i == 'c')
12+
for (i in "hello_world") {
13+
if (i == '_')
1514
break
15+
value += i.toString()
1616
}
17-
assertEquals("abc", value)
17+
assertEquals("hello", value)
1818
}
1919
@Test
2020
fun givenLoop_whenBreakWithLabel_thenComplete() {
@@ -32,12 +32,12 @@ class StructuralJumpTest {
3232
@Test
3333
fun givenLoop_whenContinue_thenComplete() {
3434
var result = ""
35-
for (i in 'a'..'d') {
36-
if (i == 'b')
35+
for (i in "hello_world") {
36+
if (i == '_')
3737
continue
3838
result += i
3939
}
40-
assertEquals("acd", result)
40+
assertEquals("helloworld", result)
4141
}
4242
@Test
4343
fun givenLoop_whenContinueWithLabel_thenComplete() {
@@ -73,37 +73,37 @@ class StructuralJumpTest {
7373
fun givenLambda_whenReturnWithExplicitLabel_thenComplete() {
7474
var result = ""
7575
"hello_world".forEach lit@{
76-
if (it == 'o') {
76+
if (it == '_') {
7777
// local return to the caller of the lambda, i.e. the forEach loop
7878
return@lit
7979
}
8080
result += it.toString()
8181
}
82-
assertEquals("hell_wrld", result)
82+
assertEquals("helloworld", result)
8383
}
8484

8585
@Test
8686
fun givenLambda_whenReturnWithImplicitLabel_thenComplete() {
8787
var result = ""
8888
"hello_world".forEach {
89-
if (it == 'o') {
89+
if (it == '_') {
9090
// local return to the caller of the lambda, i.e. the forEach loop
9191
return@forEach
9292
}
9393
result += it.toString()
9494
}
95-
assertEquals("hell_wrld", result)
95+
assertEquals("helloworld", result)
9696
}
9797

9898
@Test
9999
fun givenAnonymousFunction_return_thenComplete() {
100100
var result = ""
101101
"hello_world".forEach(fun(element) {
102102
// local return to the caller of the anonymous fun, i.e. the forEach loop
103-
if (element == 'o') return
103+
if (element == '_') return
104104
result += element.toString()
105105
})
106-
assertEquals("hell_wrld", result)
106+
assertEquals("helloworld", result)
107107
}
108108

109109
@Test

0 commit comments

Comments
 (0)