Skip to content

Commit e53074b

Browse files
committed
Control Flow Statements
1 parent d8e78de commit e53074b

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/10_default_functions.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
/*
3+
* Default Functions
4+
* */
5+
fun main(args: Array<String>) {
6+
7+
var result = findVolume(2, 3)
8+
print(result)
9+
}
10+
11+
fun findVolume(length: Int, breadth: Int, height: Int = 10): Int {
12+
13+
return length * breadth * height
14+
}

src/10_if_expression.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/*
3+
* IF as Expression
4+
* */
5+
fun main(args: Array<String>) {
6+
7+
val a = 2
8+
9+
val b = 5
10+
11+
var maxValue: Int = if (a > b) {
12+
print("a is greater")
13+
a
14+
} else {
15+
print("b is greater")
16+
b
17+
}
18+
19+
println(maxValue)
20+
}

src/11_when_expression.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
/*
4+
* WHEN as Expression
5+
* */
6+
fun main(args: Array<String>) {
7+
8+
val x = 100
9+
10+
val str: String = when (x) {
11+
12+
1 -> "x is 1"
13+
2 -> "x is 2"
14+
else -> {
15+
"x value is unknown"
16+
"x is an alien"
17+
}
18+
}
19+
20+
println(str)
21+
}

0 commit comments

Comments
 (0)