Skip to content

Commit

Permalink
docs: update range for: 0-based index rationale (#20617)
Browse files Browse the repository at this point in the history
  • Loading branch information
verulian committed Jan 21, 2024
1 parent b42dd8b commit 55287b3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/docs.md
Expand Up @@ -2058,6 +2058,16 @@ for i in 0 .. 5 {
`low..high` means an *exclusive* range, which represents all values
from `low` up to *but not including* `high`.

> [!NOTE]
> This exclusive range notation and zero-based indexing follow principles of
logical consistency and error reduction. As Edsger W. Dijkstra outlines in
'Why Numbering Should Start at Zero'
([EWD831](https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html)),
zero-based indexing aligns the index with the preceding elements in a sequence,
simplifying handling and minimizing errors, especially with adjacent subsequences.
This logical and efficient approach shapes our language design, emphasizing clarity
and reducing confusion in programming.

#### Condition `for`

```v
Expand Down

0 comments on commit 55287b3

Please sign in to comment.