]> Cypherpunks repositories - gostls13.git/commitdiff
improve the examples in the section on iota
authorRob Pike <r@golang.org>
Tue, 15 Jul 2008 22:27:31 +0000 (15:27 -0700)
committerRob Pike <r@golang.org>
Tue, 15 Jul 2008 22:27:31 +0000 (15:27 -0700)
SVN=127347

doc/go_lang.txt

index 2f102c06ccd9d2d07396883df7fc1178fb381aba..875f7b2d11ec06c148a97ba824da57bd4f4df197 100644 (file)
@@ -1499,6 +1499,22 @@ a set of related constants:
   const x = iota;  // sets x to 0
   const y = iota;  // sets y to 0
 
+Since the expression in constant declarations repeats implicitly
+if omitted, the first two examples above can be abbreviated:
+
+  const (
+    enum0 = iota;  // sets enum0 to 0, etc.
+    enum1;
+    enum2
+  )
+
+  const (
+    a = 1 << iota;  // sets a to 1 (iota has been reset)
+    b;  // sets b to 2
+    c;  // sets c to 4
+  )
+
+
 TODO: should iota work in var, type, func decls too?