Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Branching and Looping in GO
package main
import (
func main() {
go findRandomNumber(rand.Intn(100))
time.Sleep(5 * time.Second)
func findRandomNumber(randomNumber int) {
count := 1
numberFound := false
for {
number := rand.Intn(10000)
if number == randomNumber {
numberFound = true
if numberFound {
fmt.Printf("Number #%v found after %v attempt(s)", randomNumber, count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.