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

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

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -