Skip to content

Commit 8024cc7

Browse files
Merge pull request #606 from AlexanderPrendota/verifier/new-samples
New samples from kotlin-web-site
2 parents b2be773 + be59ef3 commit 8024cc7

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
fun main() {
2-
//sampleStart
3-
for (i in 1..3) {
4-
println(i)
5-
}
6-
for (i in 6 downTo 0 step 2) {
7-
println(i)
8-
}
9-
//sampleEnd
2+
val a = 2
3+
val b = 3
4+
5+
//sampleStart
6+
var max = a
7+
if (a < b) max = b
8+
9+
// With else
10+
if (a > b) {
11+
max = a
12+
} else {
13+
max = b
14+
}
15+
16+
// As expression
17+
max = if (a > b) a else b
18+
19+
// You can also use `else if` in expressions:
20+
val maxLimit = 1
21+
val maxOrLimit = if (maxLimit > a) maxLimit else if (a > b) a else b
22+
23+
//sampleEnd
24+
println("max is $max")
25+
println("maxOrLimit is $maxOrLimit")
1026
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
fun main() {
2-
val array = arrayOf("a", "b", "c")
32
//sampleStart
4-
for (i in array.indices) {
5-
println(array[i])
3+
for (i in 1..3) {
4+
println(i)
5+
}
6+
for (i in 6 downTo 0 step 2) {
7+
println(i)
68
}
79
//sampleEnd
810
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fun main() {
2-
val array = arrayOf("a", "b", "c")
2+
val array = arrayOf("a", "b", "c")
33
//sampleStart
4-
for ((index, value) in array.withIndex()) {
5-
println("the element at $index is $value")
4+
for (i in array.indices) {
5+
println(array[i])
66
}
77
//sampleEnd
88
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fun main() {
2+
val array = arrayOf("a", "b", "c")
3+
//sampleStart
4+
for ((index, value) in array.withIndex()) {
5+
println("the element at $index is $value")
6+
}
7+
//sampleEnd
8+
}

0 commit comments

Comments
 (0)