From 89d880ecd80caa438daa47c51f12116e22940351 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 9 Nov 2018 13:43:00 +0300 Subject: [PATCH] refactor: infinite kill exercise (loops) --- 13-loops/exercises/06-infinite-kill/main.go | 15 ++++++++++++++- .../exercises/06-infinite-kill/solution/main.go | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/13-loops/exercises/06-infinite-kill/main.go b/13-loops/exercises/06-infinite-kill/main.go index f65d6c81f..07eb66ce9 100644 --- a/13-loops/exercises/06-infinite-kill/main.go +++ b/13-loops/exercises/06-infinite-kill/main.go @@ -17,12 +17,14 @@ package main // then kill it using CTRL+C keys // // RESTRICTIONS -// 1. Print one of those characters randomly: \ / | +// 1. Print one of those characters randomly: \ / | - // 2. Before printing a character print also this // escape sequence: \r // // Like this: "\r/", or this: "\r|", and so on... // +// 3. NOTE : If you're using Go Playground, use "\f" instead of "\r" +// // HINTS // 1. Use `time.Sleep` to sleep. // 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. // // 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() { diff --git a/13-loops/exercises/06-infinite-kill/solution/main.go b/13-loops/exercises/06-infinite-kill/solution/main.go index 8a48502a1..a5b3e8a97 100644 --- a/13-loops/exercises/06-infinite-kill/solution/main.go +++ b/13-loops/exercises/06-infinite-kill/solution/main.go @@ -17,15 +17,17 @@ func main() { for { var c string - switch rand.Intn(3) { + switch rand.Intn(4) { case 0: c = "\\" case 1: c = "/" case 2: c = "|" + case 3: + c = "-" } - fmt.Printf("\r%s", c) + fmt.Printf("\r%s Please Wait. Processing....", c) time.Sleep(time.Millisecond * 150) } }