Go does not have a separate while keyword. Any “while” loop is written with for and a condition.
n := 1
for n < 100 {
n *= 2
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if line == "quit" {
break
}
// handle line
}
for attempt := 1; attempt <= 5; attempt++ {
if err := try(); err == nil {
break
}
time.Sleep(time.Duration(attempt) * 100 * time.Millisecond)
}
Use continue to skip to the next iteration and break to exit the innermost loop (or use a label for an outer loop).