bish icon indicating copy to clipboard operation
bish copied to clipboard

Bish for loop bounds are inclusive

Open tdenniston opened this issue 10 years ago • 2 comments

Currently, the following bish script:

for (i in 0 .. 10) {
    print("$i ");
}

will print all numbers from 0 to 10, inclusive. The usual behavior of ranges such as these is that the lower bound is inclusive, but the upper bound is exclusive. Bish should probably match this expectation.

tdenniston avatar Mar 17 '15 20:03 tdenniston

You can perhaps take a page from swift: http://www.notesfromandy.com/2014/07/30/swifts-range-operators/

official apple docs on this: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html#//apple_ref/doc/uid/TP40014097-CH6-ID73

so both .. and ...

digitalsurgeon avatar Mar 23 '15 20:03 digitalsurgeon

Thanks for the pointer to that. I'm not sure how I feel about ..< as an operator though. I also like their compromise of no semicolons but explicit blocks with curly braces. Looks like I'll have to take a closer look at Swift to see what other ideas I can borrow.

tdenniston avatar Mar 23 '15 21:03 tdenniston