Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write a function without return or Nil return type. Suggest an alternative

Tags:

go

I have a function here that loops through and print numbers. I do not have anything to return. How can I avoid this without having to return a value?

func Problem1V3() Nil {
sum := 0
    for i := 3; i < 1000; i+=3 {
        fmt.Printf("i loop: %v", i)
    }
    return Nil
}
like image 498
Anvesh Checka Avatar asked Dec 11 '22 09:12

Anvesh Checka


1 Answers

I think this should work.

func Problem1V3() {
    for i := 3; i < 1000; i+=3 {
        fmt.Printf("i loop: %v", i)
    }
}

You can run it at http://play.golang.org/p/irUI1sCx_B

like image 93
Sam Mussmann Avatar answered Feb 16 '23 01:02

Sam Mussmann