> For the complete documentation index, see [llms.txt](https://learngo.edugated.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learngo.edugated.com/functions.md).

# Functions

**Syntax:**

```
func name_of_func(first, two) return_type{

    return variable

}
```

Takes two input integer and returns an integer (common int type input if both are the same type else individually)

```
package main

import (
	"fmt"
)

func plus(a ,b int) int{

	return a + b 
}

func main() {
	
	r := plus(3,4)
	fmt.Println(r)
		
}
```

Multiple return from function

```
package main

import (
	"fmt"
)

func plus(a ,b int) (int,int){
	
	c := a + b
	d := a*b
	return c,d 
}

func main() {
	
	r,r1 := plus(3,4)
	fmt.Println(r,r1)
		
}
```

**Question:** you can also pass list

**Answer:**&#x20;

**Multiple Arguments** passing and receiving

```
package main

import (
	"fmt"
)


// receiving multiple elements as arguments in func
func sum(num ...int){
i:=0 
total := 0
for i=0; i< len(num); i++ {
	total = total + num[i]

}
fmt.Println(total)

}

func main() {
	
// variable length is denoted by ... in go

	sum(1,2)
	
	sum(1,2, 23,53,4)
	
	// passing multiple elements in collections
	nums := []int{1,2,3,4}
	sum(nums...)

}
```

**Functions examples**

![](/files/tzUvXKB2abO6qrjWH3jW)

**Closures**

* anonymous functions
* closures

```
package main

import (
	"fmt"
)


func do_something(i int) func() int{

	return func() int{
	i = i+1
	return i
	
	}
	
}

func main() {
	
	// annonymous function
	variable := do_something(3)
	fmt.Println(variable())

}
```

**Recursion**

```
package main

import (
	"fmt"
)

// passess something as an argument to function do_something
func do_something(i int) int{
// returns an anonymous function with return type
	if i == 0 {
	return 1
	}
	x := i*do_something(i-1)
	return x
}

func main() {
	// annonymous function
	fmt.Println(do_something(3))
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learngo.edugated.com/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
