Every program must start from the package name. Your first program was starting from the main package, and it was
package main
Name of the package can be different.
Than, if you need, you should import some packages, for exapmle "fmt" or "math". In "Hello world!" prog we import fmt package, because we need the Printf function, which is in these (fmt) package. Full list of packages and functions, which they have you can see on the home page of the Go language: link. It's not an mandatory part, but in more then 90% you need to export some standart packages.
Next is the program code. You can first define vars with
var name = 1
var name1 = 2*60
or something like that. Then goes functions part. The main function is "main", so if you write
func main() {
fmt.Printf("Hi! \n")
}
it will write "Hi!". Also you can write other functions:
package main
import "fmt"
var a = 1
var text string
func list() {
fmt.Printf("Hi!!!!! \n")
}
func main() {
list()
}
That's all for now. Next we'll see how to write Fibonacci number program, which is homework for lesson 1
thanks! waiting for the next lesson :)
ReplyDeletei cant wait for next lesson.i want to learn from basics.thanks
ReplyDelete