feat: add go lang for loop

This commit is contained in:
2021-01-30 12:20:43 +08:00
parent 0caab096bd
commit 22e94af0f5

View File

@@ -0,0 +1,35 @@
package main
import "fmt"
func main() {
sum := 0
for i := 1; i <= 100; i++ {
sum += i
}
fmt.Println("Sum from 1 to 100:", sum)
n := 1
for n < 1000 {
n *= 2
}
fmt.Println("n:", n)
s := 0
j := 1
for {
if j > 100 {
break
}
s += j
j++
}
fmt.Println("s: ", s)
nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
ss := 0
for _, num := range nums {
ss += num
}
fmt.Println("SS:", ss)
}