feat: init & playaround
This commit is contained in:
35
go-by-example/for/for.go
Normal file
35
go-by-example/for/for.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
// Basic
|
||||
i := 1
|
||||
for i <= 3 {
|
||||
fmt.Println(i)
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
// Classic initial/conditional/after loop
|
||||
for j := 0; j < 3; j++ {
|
||||
fmt.Println(j)
|
||||
}
|
||||
// or modernized
|
||||
for j := range 3 {
|
||||
fmt.Println("range", j)
|
||||
}
|
||||
// Will run until break
|
||||
for {
|
||||
fmt.Println("Break")
|
||||
break
|
||||
}
|
||||
// Continue
|
||||
for n := range 10 {
|
||||
if n%2 == 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Println(n)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user