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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -