Hacker News new | past | comments | ask | show | jobs | submit login

I must be getting old because I almost wish they didn't add this as it's slightly ambiguous whether it's ranging from [0, 10) or [1, 10] and anything ambiguous is probably going to haunt me at 3am some day



> anything ambiguous is probably going to haunt me at 3am some day

Man, I hope you never wondered how ERRNO behaves with CGo or that you didn't miss to update any initialization of that struct you recently added a new field to, that haunts me at 3AM.


I always just assume it is consistent to whether arrays start at [0] or [1] on whichever language I am working on.


It iterates 10 times staring with 0, seems pretty clear that the result is [0,10).


Interestingly, this does not raise any error, rather has no effect.

for i := range -10 { panic(i) }


"yes, please run this loop minus 10 times" - statements dreamed up by the utterly Deranged


Back in my days, you had to do it this way

for i := 0; i <=-10; i++{

  panic

}


Back in my day you would do

    for (size_t i = 0; i < -10; i++) {
        panic
    }
And it would panic 18446744073709551606 times.


Sure, presumably for the same reason a C-style for loop wouldn't do anything weird there either.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: