-
-
Save PatilShreyas/eea6e6fb8b7bd456636087ea8aec55ad to your computer and use it in GitHub Desktop.
This file contains 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 main() { | |
for (i in 0..10) { print(i) } // 012345678910 | |
for (i in 1 until 10) { print(i) } // 123456789 (10 is excluded) | |
for (i in 9 downTo 0) { print(i) } // 9876543210 | |
for (i in 2..20 step 2) { print("$i ") } // 2 4 6 8 10 12 14 16 18 20 | |
if (50 in 0..100) println(true) else println(false) // true | |
val list = listOf(1, 2, 3, 4, 5) | |
if (3 in list) println("3 PRESENT") else println("3 ABSENT") // 3 PRESENT | |
if (10 !in list) println("10 NOT PRESENT") else println("10 PRESENT") // 10 NOT PRESENT | |
} |
This file contains 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 main() { | |
val batteryPercentage = 90 | |
val message = when (batteryPercentage) { | |
in 1..20 -> "Very low" | |
in 21..50 -> "Low" | |
in 51..80 -> "Medium" | |
in 81..100 -> "Charged" | |
else -> "Invalid" | |
} | |
println(message) // Charged | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment