‘in’ operator in Kotlin

This post was originally posted at https://agrawalsuneet.github.io/blogs/in-operator-in-kotlin/ and reposted on Medium on 24th Nov 2017.
val count = 5;
if (count in 1..10 && count !in 5..7) {
print(“Number is between range 1 to 10 but not between 5 to 7”)
}
val array: IntArray = intArrayOf(1, 2, 3, 4, 5)
if (count in array) {
print(“Number is present in property array”)
}
when (count) {
in 11..20 -> print(“Number is between 10 and 20 including both”)
!in 21..30 -> print(“Number is not between 21 to 30”)
in array -> print(“Number is present in property array”)
!in array -> print(“Number is not present in property array”)
}
for (item in 1..10){
print(“iterates loop from 1 to 10”)
}
for (item in array){
print(“iterates all items in array”)
}

--

--

https://agrawalsuneet.github.io/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store