Application
Create new folder named src. In src folder, create new file named main.go as below:
package main
import "fmt"
func main() {
fmt.Println("Demo 1")
Demo1()
fmt.Println("\nDemo 2")
Demo2()
fmt.Println("\nDemo 3")
Demo3()
fmt.Println("\nDemo 4")
Demo4()
}
func Demo1() {
i := 1
for i <= 10 {
fmt.Printf("%3d", i)
i++
}
}
func Demo2() {
ch := 'a'
for ch <= 'z' {
fmt.Printf("%3c", ch)
ch++
}
}
func Demo3() {
var total int = 0
i := 1
for i <= 10 {
total += i
i++
}
fmt.Println("Total: ", total)
}
func Demo4() {
var counter int = 0
i := 1
for i <= 10 {
if i%2 == 0 {
counter++
}
i++
}
fmt.Println("Counter: ", counter)
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Demo 1
1 2 3 4 5 6 7 8 9 10
Demo 2
a b c d e f g h i j k l m n o p q r s t u v w x y z
Demo 3
Total: 55
Demo 4
Counter: 5