From c2a8b55d705d465e8a27f51781acf98350d98df4 Mon Sep 17 00:00:00 2001 From: Steven Degutis Date: Fri, 16 Mar 2012 07:00:35 -0500 Subject: [PATCH] enumeration --- about_enumeration.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 about_enumeration.go diff --git a/about_enumeration.go b/about_enumeration.go new file mode 100644 index 0000000..7739519 --- /dev/null +++ b/about_enumeration.go @@ -0,0 +1,28 @@ +package go_koans + +func testEnumeration() { + { + var concatenated string + var total int + + strings := []string{"hello", " world", "!"} + for i, v := range strings { + total += i + concatenated += v + } + + assert(concatenated == __string__) // for loops have a modern variation + assert(total == __int__) // which offers both a value and an index + } + + { + var totalLength int + + strings := []string{"hello", " world", "!"} + for _, v := range strings { + totalLength += len(v) + } + + assert(totalLength == __int__) // although we may omit either value + } +}