Created
December 10, 2021 20:32
-
-
Save cgrotz/3c3ffcc490e5ba633158dd4f057b61f7 to your computer and use it in GitHub Desktop.
Assigning values in Kotlin with a condition
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
var name = "Bob"; | |
String message; | |
if(name.equals("Bob")) { | |
message = "Hello Bob"; | |
} | |
else { | |
message = "Good Day Sir"; | |
} | |
System.out.println("Message is: "+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
var name = "Bob"; | |
String message; | |
switch(name) { | |
case "Bob": | |
message = "Hello Bob"; | |
break; | |
default: | |
message = "Good Day Sir"; | |
} | |
System.out.println("Message is: "+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
var name = "Bob"; | |
var message = if(name.equals("Bob")) { | |
"Hello Bob" | |
} | |
else { | |
"Good Day Sir" | |
} | |
println("Message is: ${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
var name = "Bob"; | |
var message = when(name) { | |
"Bob" -> "Hello Bob" | |
else -> "Good Day Sir" | |
} | |
println("Message is: ${message}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment