Handling Radio buttons

Hi,

I saw this code here https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/04.2.html for handling radio button input from forms.

I don’t understand how it works.

slice:=[]int{1,2}

for _, v := range slice {
if v == r.Form.Get(“gender”) {
return true
}
}
return false

The first line creates a slice named “slice”.
The for loop iterates over the slice and compares each element of the slice against the value returned by r.Form.Get("gender"). If both are equal, the loop exits immediately by returning true.
Else the function returns false after the loop.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.