August 2019
Beginner to intermediate
798 pages
17h 2m
English
This section will display multiple examples of for loops. The name of the file is loops.go and will be presented in four parts. The first code segment of loops.go is next:
package main
import (
"fmt"
)
func main() {
for i := 0; i < 100; i++ {
if i%20 == 0 {
continue
}
if i == 95 {
break
}
fmt.Print(i, " ")
}
The preceding code shows a typical for loop, as well as the use of the continue and break keywords.
The next code segment is the following:
fmt.Println()
i := 10
for {
if i < 0 {
break
}
fmt.Print(i, " ")
i--
}
fmt.Println()
The offered code emulates a typical while loop. Note the use of the break keyword to exit the for loop.
The third part of loops.go is next:
i = 0 anExpression := true for ok := ...
Read now
Unlock full access