aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/go1.22/main.go
blob: 80f6c887b3a4f6d15ef30d3759d03773990745f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

func main() {
	testIntegerRange()
	testLoopVar()
}

func testIntegerRange() {
	for i := range 10 {
		println(10 - i)
	}
	println("go1.22 has lift-off!")
}

func testLoopVar() {
	var f func() int
	for i := 0; i < 1; i++ {
		if i == 0 {
			f = func() int { return i }
		}
	}
	// Variable n is 1 in Go 1.21, or 0 in Go 1.22.
	n := f()
	if n == 0 {
		println("loops behave like Go 1.22")
	} else if n == 1 {
		println("loops behave like Go 1.21")
	} else {
		println("unknown loop behavior")
	}
}