From 55287b31eec4383cdec7058800390e17714a42d2 Mon Sep 17 00:00:00 2001 From: Veru <48661312+verulian@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:02:15 -0500 Subject: [PATCH] docs: update range `for`: 0-based index rationale (#20617) --- doc/docs.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 8283f50817d2d2..b77f92f3217d8d 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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