The Go language simulates the infinite loop method of while statements

  • 2020-05-24 05:41:45
  • OfStack

This article illustrates an example of how the Go language simulates an infinite loop of while statements. Share with you for your reference. The specific implementation method is as follows:

This code USES the for statement as the while(true) of the C language for an infinite loop

package main
import "fmt"
func main() {
    sum := 0
    for {
        sum ++
        if sum > 10{
            break
        }else{
            fmt.Println(sum)
        }
    }
}

I hope this article has been helpful to your programming of Go language.


Related articles: