I'm making a program in Go for guessing a random number. I'm having issues with a for loop.
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")
}
}