From 614276cb3ba1c7dbcf1c3f6c4b115a1fc8cb8635 Mon Sep 17 00:00:00 2001 From: Boris Bakshiyev Date: Sun, 16 Apr 2017 14:28:25 +0300 Subject: [PATCH] More efficient You should use `||` instead of `else`. --- 13_exercise-solutions/07_threeFive/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/13_exercise-solutions/07_threeFive/main.go b/13_exercise-solutions/07_threeFive/main.go index eaacdadc..8be90787 100644 --- a/13_exercise-solutions/07_threeFive/main.go +++ b/13_exercise-solutions/07_threeFive/main.go @@ -5,15 +5,14 @@ import "fmt" func main() { counter := 0 for i := 0; i < 1000; i++ { - if i%3 == 0 { - counter += i - } else if i%5 == 0 { + if i%3 == 0 || i%5 == 0 { counter += i } } fmt.Println(counter) } + /* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.