for in range, range size and indexing
This commit is contained in:
1 parent
dcab60b7bb
commit
d2c732ceef
6 files changed
+165
-119
No files matched your search
+21
-1
@@ -51,7 +51,6 @@ This might be confusing, but the range size and limits are used with for loops
|
||||
so their meaning is special.
|
||||
|
||||
For open ranges, size throws and exception.
|
||||
|
||||
For Int ranges, the `size` is `end` - `start` possibly + 1 for ind-inclusive ranges, and indexing getter returns all values from start to end, probably, inclusive:
|
||||
|
||||
val r = 1..3
|
||||
@@ -86,6 +85,27 @@ but
|
||||
>>> 2
|
||||
>>> void
|
||||
|
||||
## Character ranges
|
||||
|
||||
You can use Char as both ends of the closed range:
|
||||
|
||||
val r = 'a' .. 'c'
|
||||
assert( 'b' in r)
|
||||
assert( 'e' !in r)
|
||||
assert( 'c' == r[2] )
|
||||
for( ch in r )
|
||||
println(ch)
|
||||
>>> a
|
||||
>>> b
|
||||
>>> c
|
||||
>>> void
|
||||
|
||||
Exclusive end char ranges are supported too:
|
||||
|
||||
('a'..<'c').size
|
||||
>>> 2
|
||||
|
||||
|
||||
# Instance members
|
||||
|
||||
| member | description | args |
|
||||
|
||||
Reference in new issue
Block a user