Last active
April 22, 2021 08:00
-
-
Save davidmigloz/ee9e14a7a4a9f43e6e7088a2f87fd0e7 to your computer and use it in GitHub Desktop.
Dart vs Kotlin: conditional expressions
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
void main() { | |
final score = 7; | |
final result = score >= 5 ? "Passed" : "Failed"; | |
String message; | |
switch (result) { | |
case "Passed": | |
message = "Congratulations!"; | |
break; | |
case "Failed": | |
message = "Keep trying!"; | |
break; | |
default: | |
message = "Do you know your result?"; | |
} | |
print(message); | |
} |
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 main() { | |
val score = 7 | |
val result = if(score >= 5) "Passed" else "Failed" | |
val message = when (result) { | |
"Passed" -> "Congratulations!" | |
"Failed" -> "Keep trying!" | |
else -> "Do you know your result?" | |
} | |
println(message) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment