This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun surroundingFunction() { | |
val intList = listOf(1, 2, 3, 4, 5) | |
intList.forEach { | |
if (it % 2 == 0) { | |
return@forEach | |
} | |
} | |
println("End of surroundingFunction()") // Now, it will execute | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
intList.forEach myLabel@ { | |
if (it % 2 == 0) { | |
return@myLabel | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun surroundingFunction() { | |
val intList = listOf(1, 2, 3, 4, 5) | |
intList.forEach { | |
if (it % 2 == 0) { | |
return@forEach | |
} | |
} | |
println("End of surroundingFunction()") // Now, it will execute | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
intList.forEach myLabel@ { | |
if (it % 2 == 0) { | |
return@myLabel | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Circle { | |
fun calculateArea(radius: Double): Double { | |
require(radius > 0, { "Radius must be greater than 0" }) | |
return Math.PI * Math.pow(radius, 2.0) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val circle = Circle() | |
print(circle.calculateArea(4.5)) // will print "63.61725123519331" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val stringList: List<String> = listOf("in", "the", "club") | |
print(stringList.last{ it.length == 3}) // will print "the" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val strLenThree = stringList.last( fun(string): Boolean { | |
return string.length == 3 | |
}) | |
print(strLenThree) // will print "the" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun surroundingFunction() { | |
val intList = listOf(1, 2, 3, 4, 5) | |
intList.forEach ( fun(number) { | |
if (number % 2 == 0) { | |
return | |
} | |
}) | |
println("End of surroundingFunction()") // statement executed | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printCircumferenceAndArea(radius: Double): Unit { | |
fun calCircumference(radius: Double): Double = (2 * Math.PI) * radius | |
val circumference = "%.2f".format(calCircumference(radius)) | |
fun calArea(radius: Double): Double = (Math.PI) * Math.pow(radius, 2.0) | |
val area = "%.2f".format(calArea(radius)) | |
print("The circle circumference of $radius radius is $circumference and area is $area") | |
} |