Forráskód Böngészése

Update documentation.

Vladislav Folts 9 éve
szülő
commit
29233002be

+ 34 - 0
doc/wiki/eberon-FOR..IN.md

@@ -0,0 +1,34 @@
+*FOR..IN* loop statement is used to iteratate through arrays and [[MAP|eberon-associative-arrays]]s. For arrays all elements are iterated from the beginning to the end.
+
+### Syntax
+
+    FOR [key,] value IN array DO
+        ...
+    END;
+
+_key_ is an optional variable standing for array's index (from 0 to LEN(_array_) - 1) or MAP's key. _key_ type is INTEGER for arrays and [[STRING|eberon-strings]] for [[MAP|eberon-associative-arrays]]s.
+_value_ is a variable standing for element's value.
+These variables have no a separate declaration and their visibility scope is inside loop only. Also these variables are read-only - similar to non-VAR parameters.
+
+### Example
+
+    VAR
+        a: ARRAY 3 OF BOOLEAN;
+    BEGIN
+        FOR i, v IN a DO
+            ASSERT(a[i] = v);
+        END;
+
+        (* not using key here *)
+        FOR v IN a DO
+        END;
+    END;
+
+    VAR
+        m: MAP OF INTEGER;
+    BEGIN
+        FOR k, v IN m DO
+            ASSERT(v = 0);
+            ASSERT(k # "");
+        END;
+    END;

+ 1 - 5
doc/wiki/eberon-associative-arrays.md

@@ -19,12 +19,8 @@ Keyword *IN* is used to test whether element with specified key is present in th
     
     IF key IN m THEN
 
-It is also possible to iterate through associative array keys/values using *FOR..IN* loop:
+It is also possible to iterate through associative array keys/values using [[FOR..IN|eberon-FOR..IN]] loop.
     
-    FOR key, value IN m DO END
-
-Here _key_ and _value_ are variables assigned to each key/value pair while iterating through array. These variables have no a separate declaration and their visibility scope is inside loop only. Also these variables are read-only - similar to non-VAR parameters.
-
 To remove element from array *remove* method is used:
     
     m.remove(key)

+ 1 - 0
doc/wiki/eberon.md

@@ -10,6 +10,7 @@ Eberon basically extends original Oberon (excluding additional [restrictions](#r
 * [[Implicit Type Narrowing|eberon-implicit-type-narrowing]]
 * [[Dynamic Arrays|eberon-dynamic-arrays]]
 * [[Associative Arrays|eberon-associative-arrays]]
+* [[FOR..IN loop|eberon-FOR..IN]]
 * [[Array indexOf() method|eberon-array-methods]]
 * [[Record fields read-only export|eberon-record-fields-read-only-export]]
 * [[Procedure call result can be denoted|eberon-procedure-call-result]]