From 19a36c9acb9383c8be8390abb4f05c01abd1956d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sun, 9 Jun 2013 15:34:25 +0200 Subject: [PATCH] Documents shortcut array syntax. Refs #397. --- doc/tut1.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/tut1.txt b/doc/tut1.txt index 28e23b0f0..0cc9b05c1 100644 --- a/doc/tut1.txt +++ b/doc/tut1.txt @@ -1182,6 +1182,21 @@ type and instead write it embedded directly as the type of the first dimension: type TLightTower = array[1..10, array[north..west, TBlinkLights]] +It is quite frequent to have arrays start at zero, so there's a shortcut syntax +to specify a range from zero to the specified index minus one: + +.. code-block:: nimrod + type + TIntArray = array[0..5, int] # an array that is indexed with 0..5 + TQuickArray = array[6, int] # an array that is indexed with 0..5 + var + x: TIntArray + y: TQuickArray + x = [1, 2, 3, 4, 5, 6] + y = x + for i in low(x)..high(x): + echo(x[i], y[i]) + Sequences ---------