我如何摆脱无限循环的Golang [关闭]

I'm making a program in Go for guessing a random number. I'm having issues with a for loop.

  1. I can't stop the for loop from continuously iterating.
  2. How do i break out of the loop once a condition is satisfied.

    for loop == true {
    
    //fmt.Println("read number", i, "/n")
    if i == ans {
        fmt.Println("well done")
    }
    if i != ans {
        fmt.Println("Nope")
        fmt.Scan(i)
    }
    

You need to break out of the loop:

for {
    fmt.Scan(i)
    if i == ans {
        fmt.Println("well done")
        break
    }
    if i != ans {
        fmt.Println("Nope")
    }
}