Skip to content

Commit 3b4e23c

Browse files
refactor some code
1 parent 6c0c944 commit 3b4e23c

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class StructuralJumpTest {
1414
for (i in 1..10) {
1515
value = i
1616
if (value == 3)
17-
break;
17+
break
1818
}
1919

2020
assertEquals(value, 3)
@@ -24,7 +24,7 @@ class StructuralJumpTest {
2424
for (j in 1..10) {
2525
value = i * j
2626
if (value == 30)
27-
break@outer_loop;
27+
break@outer_loop
2828
}
2929
}
3030

@@ -37,7 +37,7 @@ class StructuralJumpTest {
3737
//continue loop without label
3838
for (i in 1..10) {
3939
if (i == 3)
40-
continue;
40+
continue
4141
processedList.add(i)
4242
}
4343

@@ -48,7 +48,7 @@ class StructuralJumpTest {
4848
outer_loop@ for (i in 1..10) {
4949
for (j in 1..10) {
5050
if (i == 3)
51-
continue@outer_loop;
51+
continue@outer_loop
5252
processedList.add(i*j)
5353
}
5454
}
@@ -63,12 +63,12 @@ class StructuralJumpTest {
6363
assert(it < 3)
6464
}
6565
//this point is unreachable
66-
assert(false);
66+
assert(false)
6767
}
6868

6969
@Test
7070
fun givenLambda_whenReturnWithExplicitLabel_thenComplete() {
71-
var result = mutableListOf<Int>();
71+
var result = mutableListOf<Int>()
7272

7373
listOf(1, 2, 3, 4, 5).forEach lit@{
7474
if (it == 3) {
@@ -78,12 +78,12 @@ class StructuralJumpTest {
7878
result.add(it)
7979
}
8080

81-
assert(result.all { it -> it != 3 });
81+
assert(result.all { it -> it != 3 })
8282
}
8383

8484
@Test
8585
fun givenLambda_whenReturnWithImplicitLabel_thenComplete() {
86-
var result = mutableListOf<Int>();
86+
var result = mutableListOf<Int>()
8787

8888
listOf(1, 2, 3, 4, 5).forEach {
8989
if (it == 3) {
@@ -93,26 +93,26 @@ class StructuralJumpTest {
9393
result.add(it)
9494
}
9595

96-
assert(result.all { it -> it != 3 });
96+
assert(result.all { it -> it != 3 })
9797
}
9898

9999
@Test
100100
fun givenAnonymousFunction_return_thenComplete() {
101-
var result = mutableListOf<Int>();
101+
var result = mutableListOf<Int>()
102102
listOf(1, 2, 3, 4, 5).forEach(fun(element: Int) {
103103
if (element == 3) return // local return to the caller of the anonymous fun, i.e. the forEach loop
104-
result.add(element);
104+
result.add(element)
105105
})
106106

107-
assert(result.all { it -> it != 3 });
107+
assert(result.all { it -> it != 3 })
108108
}
109109

110110
@Test
111111
fun givenAnonymousFunction_returnToLabel_thenComplete() {
112-
var value = 0;
112+
var value = 0
113113
run loop@{
114114
listOf(1, 2, 3, 4, 5).forEach {
115-
value = it;
115+
value = it
116116
if (it == 3) return@loop // non-local return from the lambda passed to run
117117
}
118118
}

0 commit comments

Comments
 (0)