December 2018
Beginner
452 pages
12h 17m
English
In reality, you will not use a while loop that often. In most scenarios, a for loop is better (as we will see later on in this chapter). There is, however, one situation where a while loop is excellent: dealing with user input. If you use the while true construct with an if-then-else block nesting within it, you can keep asking the user for input until you get the answer you're looking for. The following example, which is a simple riddle, should clarify matters:
reader@ubuntu:~/scripts/chapter_11$ vim while-interactive.sh reader@ubuntu:~/scripts/chapter_11$ cat while-interactive.sh #!/bin/bash###################################### Author: Sebastiaan Tammer# Version: v1.0.0# Date: 2018-10-27# Description: ...