github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/loopvar/testdata/for_nested.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  )
    11  
    12  func main() {
    13  	x := f(60)
    14  	fmt.Println(x)
    15  	if x != 54 {
    16  		os.Exit(11)
    17  	}
    18  }
    19  
    20  var escape *int
    21  
    22  func f(i int) int {
    23  	a := 0
    24  outer:
    25  	for {
    26  		switch {
    27  		case i > 55:
    28  			i--
    29  			continue
    30  		case i == 55:
    31  			for j := i; j != 1; j = j / 2 {
    32  				a++
    33  				if j == 4 {
    34  					escape = &j
    35  					i--
    36  					continue outer
    37  				}
    38  				if j&1 == 1 {
    39  					j = 2 * (3*j + 1)
    40  				}
    41  			}
    42  			return a
    43  		case i < 55:
    44  			return i
    45  		}
    46  	}
    47  }