Para loop em Golang
for count := 0; count <= 10; count++ {
fmt.Println("My counter is at", count)
}
Harendra
for count := 0; count <= 10; count++ {
fmt.Println("My counter is at", count)
}
// Program to print the first 5 natural numbers
package main
import "fmt"
func main() {
// for loop terminates when i becomes 6
for i := 1; i <= 5; i++ {
fmt.Println(i)
}
}
import (
"fmt"
)
func main() {
numbs := []int{1, 2, 3, 4, 5}
for numb := range numbs {
fmt.Printf("using range: %d \n", numb)
}
fmt.Println("\n")
for i := 0; i < len(numbs); i++ {
fmt.Printf("using for: %d \n", i)
}
fmt.Println("\n")
i := 0
for i < len(numbs) {
fmt.Printf("using for like while: %d \n", i)
i++
}
}
// Reverse a
for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
a[i], a[j] = a[j], a[i]
}
for initialization; condition; update {
statement(s)
}
// Program to print the sum of natural numbers: 1 + 2 + 3 + ... +n
package main
import "fmt"
func main() {
var n, sum = 10, 0
for i := 1 ; i <= n; i++ {
sum += i // sum = sum + i
}
fmt.Println("sum =", sum)
}