Hello World

// this is a comment. It's ignored by the compiler. By convention, we describe each package in a
// comment immediately preceding its package declaration. 
package main // compiler entry point

import "fmt"

// define and declare a variable outside a function. hello has global scope
// variables are stored on the stack and are declared to zero value of type: ""
var hello string

// every module can have one init. Init runs after any variable initialization and
// before any function
func init() {
    hello = "Hello World"
}

func main() { // declaration of entry point
    printHelloWorld(hello)

    ciao := "Ciao Mondo" // := short variable declaration can be used only inside functions.
    printHelloWorld(ciao)
}

func printHelloWorld(s string) {
    fmt.Println(s)
}

Output:

Hello World
Ciao Mondo

results matching ""

    No results matching ""