2 ms·
> That is more annoying for [closed,open) because it turns into the abhorent (open,closed]. What's wrong with (open, closed] ?? Especially if you're going back
by dragontamer 4y ago
> That is more annoying for [closed,open) because it turns into the abhorent (open,closed].
What's wrong with (open, closed] ?? Especially if you're going backwards?
for(int i=559; i>554; i--){
//do stuff with i
}
Perhaps the most important reason to do zero-indexed + [closed,open> and <open, closed] is because these are the defaults the C / C++ / Java for loops assume you're doing.
Its all non-intuitive because humans are really bad with off-by-one errors.
------
EDIT: I guess familiarity with [closed, closed] is somewhat important, because other programmers like the form. The pattern here is: for(int i=start_closed; i<=end_closed; i++), if anyone's curious.
- lupire 4y agoNo one really wants [x, y). That want [0,y) or [x,x+y) because y is the length of the interval. So no one wants (y,x] when going backwards, because x<>0 there.
- ufo 4y agoThe problem with that example is that you had to ±1 both of the ends of the original range. That is, you started with [555,560) and had to rewrite it to (554,559] for the reverse loop.