OneBite.Dev - Coding blog in a bite size

declare a void function without return value in Go

Code snippet on how to declare a void function without return value in Go

  func DoSomething() {
    // code goes here
  }

This code declares a function named “DoSomething” in Go without a return value. To begin, the keyword “func” is used to declare the function and its name is “DoSomething”. After that, brackets ”()” follows to define any parameter that is needed for the function. In this case, since the function is declared “void”, there is no parameter defined. Then, inside the brackets a code block is written that the function will execute. In this case, there is no code written in the function, but if there were any it would be written between the curly braces.

go