-
Notifications
You must be signed in to change notification settings - Fork 0
/
looping03.go
27 lines (20 loc) · 862 Bytes
/
looping03.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Alta3 Research | RZFeeser
Looping - for loop behaving like a while loop (improved) */
package main
import "fmt"
import "math/rand"
import "time" // we will draw a random value from this
func main() {
// this next line will allow us to "seed" randomness into our program
// and get some different results each time we run the program
rand.Seed(time.Now().UnixNano()) // create some randomness
drive := 0 // drive is defined at the function level
fmt.Print("Get a mulligan on any drive under 60 yards.\n")
// with no init or post statements, we can completely drop the requirements
// for use of semi colons
for drive <= 60 { // "as long as" driver is less than or equal to 60
drive = rand.Intn(251)
fmt.Print("SWING!\n")
}
fmt.Println("Your longest drive was", drive, "yards")
}