Advertisement
Koepnick

functions

Jan 15th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.49 KB | None | 0 0
  1. // Functions are declared thusly
  2. // func function_name(varname vartype, ...) vartype { }
  3.  
  4. func example(x int, y int) int {
  5.     return x * y
  6. }
  7.  
  8. func example2( x, y int) int {
  9.     return x + y
  10. }
  11.  
  12. func example3(x, y int) (int, string) {
  13.     return (x*y), "Use i,s := example3(5, 9)"
  14. }
  15.  
  16. func example4(x int) (y, z int) {
  17.     // Here the return variables are explicitly named in the function declaration
  18.     y = x / 10
  19.     z = x * 10
  20.     // This allows us to do a naked return with implicit values
  21.     return
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement