On 3 May 2017 at 09:36, Egon <egonel...@gmail.com> wrote: > On Wednesday, 3 May 2017 07:34:16 UTC+3, Tong Sun wrote: >> >> Hi, >> >> How to use `iota` to define consts that have gap(s) in them? >> >> E.g., If my consts are, >> >> 1, 2, 3, 7, 8, 9 >> >> How to use iota to define them? Thx. > > > You don't have to use iota. If these are predefined constants, such as a > protocol -- it's usually better to assign them explicitly rather than to use > iota. > > There are also: > > // use skip > const ( > A = iota > B > C > D = iota + 3 // for skip 3
I think this is slightly misleading - this idiom doesn't skip three - it adds 3 to the current value of iota. For example, given const ( A = iota B C D = iota + 10 E F = iota + 2 G ) G will be 8, not 18. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.