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
for(i in 0..3) { // 1 | |
print(i) | |
} | |
print(" ") | |
for(i in 0 until 3) { // 2 | |
print(i) | |
} | |
print(" ") | |
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
for (char in 'a'..'d') { // 1 | |
println(char) | |
} | |
for (char in 'z' downTo 's' step 2) { // 2 | |
println(char) | |
} |
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
val jobs = setOf("Baker", "Driver", "Dentist") | |
val works = setOf("Dentist", "Baker", "Driver") | |
println(jobs == works) // true | |
println(jobs === works) // false |
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 minOf(a: Int, b: Int) = if (a < b) a else b |
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
var number = 4 | |
var numberString = when(number) { | |
1 -> "One" | |
2 -> "Two" | |
3 -> "Three" | |
4 -> "Four" | |
5 -> "Five" | |
else -> "invalid number" | |
} | |
println("String of number $numberString") |
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
var a: Int? = null // a değişkeni null | |
a?.let { | |
print(it) // a null olduğu için let ile bu kod bloğuna girmez | |
} | |
a = 2 // a değişti, null değil | |
a?.let { | |
print(it) // scope içine girer ve a yı yazdırır | |
} |
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
var a: Int? = null | |
a?.let(::print) | |
a = 2 | |
a?.let(::print) |
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
data class Person(var name: String, var age: Int = 0, var city: String = "",var country: String = "") | |
val adam = Person("Adam") | |
adam.age = 24 | |
adam.city = "Amsterdam" | |
adam.country = "Germany" | |
println(adam) |
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
data class Person(var name: String, var age: Int = 0, var city: String = "",var country: String = "") | |
val adam = Person("Adam").apply { | |
age = 24 | |
city = "Amsterdam" | |
country = "Germany" | |
} | |
println(adam) |
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
data class Person(var name: String, var age: Int = 0, var city: String = "",var country: String = "") | |
val adam = Person("Adam").apply { | |
age = 24 | |
city = "Amsterdam" | |
country = "Germany" | |
} | |
with(adam){ | |
print("$age") | |
} |