Creating exclusive ranges in kotlin -
i starting kotlin. want create range 1 n n excluded. found out kotlin has ranges , can use them follows
1..n
but inclusive range includes 1 , n. how create exclusive ranges.
not sure if best way can define int extension creates intrange (lower bound +1) (upper bound - 1).
fun int.exclusiverangeto(other: int): intrange = intrange(this + 1, other - 1) and use in way:
for (i in 1 exclusiverangeto n) { //... } here can find more details how ranges work.
Comments
Post a Comment