Ranges inclusive or exclusive with regard to upper bound?

Hi, I have tried to figure out whether ranges are including or excluding the upper bound in Zig, or if you can choose, but I was somewhat confused. After some research and testing, I came to the conclusion that:

  • for ranges use .. (two dots) and are always exclusive regarding the upper bound
  • switch ranges use ... (three dots) and are always inclusive regarding the upper bound

And you cannot use the two dot syntax in switch or the three dot syntax in for, right?

Sorry to ask, I just want to be sure I understand right.

P.S.: I forgot about slice indices (which seem to be like for ranges?).

Correct. Slicing is [a..b) (exclusive).

Extensively discussed a few months ago, and appears to me to be unlikely to change. (unless perhaps something compelling comes up while implementing ranged integers, if that even happens).

2 Likes

Actually, the OP is the answer, because it is correct. But thanks :slight_smile: