I'm a freshman for go language, and some basic things i want to ask how can we make sense for this function.
we need to use "strconv" to fix this issue.
package main
import (
"fat"
"strconv"
)
type Student struct {
Name string
}
func (stu *Student) Leave() {
fmt.Println(stu.Name + " Leaving")
}
func (stu *Student) Present() {
fmt.Println("I am " + stu.Name)
}
func main() {
fmt.Println("Start of session")
for i := 0; i < 6; i++ {
s := Student{Name: fmt.Sprintf("Student%d", i)}
s.Present()
fmt.Println("Room Empty")
defer s.Leave()
}
fmt.Println("End of session")
}
The output should be like this
Start of session
I am Student0
I am Student1
I am Student2
I am Student3
I am Student4
I am Student5
End of session
Student5 Leaving
Student4 Leaving
Student3 Leaving
Student2 Leaving
Student1 Leaving
Student0 Leaving
Room Empty
We need to write only one main function() and a simple for loop to get the result.