Skip to content

Commit

Permalink
Control Flow Statements
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Sep 16, 2018
1 parent d8e78de commit e53074b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/10_default_functions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/*
* Default Functions
* */
fun main(args: Array<String>) {

var result = findVolume(2, 3)
print(result)
}

fun findVolume(length: Int, breadth: Int, height: Int = 10): Int {

return length * breadth * height
}
20 changes: 20 additions & 0 deletions src/10_if_expression.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/*
* IF as Expression
* */
fun main(args: Array<String>) {

val a = 2

val b = 5

var maxValue: Int = if (a > b) {
print("a is greater")
a
} else {
print("b is greater")
b
}

println(maxValue)
}
21 changes: 21 additions & 0 deletions src/11_when_expression.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


/*
* WHEN as Expression
* */
fun main(args: Array<String>) {

val x = 100

val str: String = when (x) {

1 -> "x is 1"
2 -> "x is 2"
else -> {
"x value is unknown"
"x is an alien"
}
}

println(str)
}

0 comments on commit e53074b

Please sign in to comment.