refactor: infinite kill exercise (loops)
This commit is contained in:
@ -17,12 +17,14 @@ package main
|
|||||||
// then kill it using CTRL+C keys
|
// then kill it using CTRL+C keys
|
||||||
//
|
//
|
||||||
// RESTRICTIONS
|
// RESTRICTIONS
|
||||||
// 1. Print one of those characters randomly: \ / |
|
// 1. Print one of those characters randomly: \ / | -
|
||||||
// 2. Before printing a character print also this
|
// 2. Before printing a character print also this
|
||||||
// escape sequence: \r
|
// escape sequence: \r
|
||||||
//
|
//
|
||||||
// Like this: "\r/", or this: "\r|", and so on...
|
// Like this: "\r/", or this: "\r|", and so on...
|
||||||
//
|
//
|
||||||
|
// 3. NOTE : If you're using Go Playground, use "\f" instead of "\r"
|
||||||
|
//
|
||||||
// HINTS
|
// HINTS
|
||||||
// 1. Use `time.Sleep` to sleep.
|
// 1. Use `time.Sleep` to sleep.
|
||||||
// 2. You should pass a `time.Duration` value to it.
|
// 2. You should pass a `time.Duration` value to it.
|
||||||
@ -36,6 +38,17 @@ package main
|
|||||||
// lucky number lecture. Even then so, then just skip it.
|
// lucky number lecture. Even then so, then just skip it.
|
||||||
//
|
//
|
||||||
// You can return back to it afterwards.
|
// You can return back to it afterwards.
|
||||||
|
//
|
||||||
|
// EXPECTED OUTPUT
|
||||||
|
// - The program should display the following messages in any order.
|
||||||
|
// - And, the first character (\, -, /, or |) should be randomly
|
||||||
|
// displayed.
|
||||||
|
// - \r or \f sequence will clear the line.
|
||||||
|
//
|
||||||
|
// \ Please Wait. Processing....
|
||||||
|
// - Please Wait. Processing....
|
||||||
|
// / Please Wait. Processing....
|
||||||
|
// | Please Wait. Processing....
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -17,15 +17,17 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
var c string
|
var c string
|
||||||
|
|
||||||
switch rand.Intn(3) {
|
switch rand.Intn(4) {
|
||||||
case 0:
|
case 0:
|
||||||
c = "\\"
|
c = "\\"
|
||||||
case 1:
|
case 1:
|
||||||
c = "/"
|
c = "/"
|
||||||
case 2:
|
case 2:
|
||||||
c = "|"
|
c = "|"
|
||||||
|
case 3:
|
||||||
|
c = "-"
|
||||||
}
|
}
|
||||||
fmt.Printf("\r%s", c)
|
fmt.Printf("\r%s Please Wait. Processing....", c)
|
||||||
time.Sleep(time.Millisecond * 150)
|
time.Sleep(time.Millisecond * 150)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user