Another way to read multiple inputs within a loop which can handle an input with spaces:
package main
import (
"fmt"
"bufio"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
var text string
for text != "q" { // break the loop if text == "q"
fmt.Print("Enter your text: ")
scanner.Scan()
text = scanner.Text()
if text != "q" {
fmt.Println("Your text was: ", text)
}
}
}
Output:
Enter your text: Hello world!
Your text was: Hello world!
Enter your text: Go is awesome!
Your text was: Go is awesome!
Enter your text: q