Go Basics

Print a message from main.

Go
package main
import "fmt"
func main() {
  name := "Ada"
  fmt.Println("Hello,", name)
}
Output
Hello, Ada

Explanation

A runnable Go program uses package main and a main function. Import fmt for formatted input and output.

Explore the dry run
Guided walkthroughReady
1package main
2import "fmt"
3func main() {
4 name := "Ada"
5 fmt.Println("Hello,", name)
6}

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Declare name with inferred string type.name = "Ada"
—
Print the greeting and name with a space.name = "Ada"
Hello, Ada