March 2002
Beginner
504 pages
10h 47m
English
So far you have looked at creating loops and working with loops to accomplish different tasks. Sometimes you will need to stop a loop or skip iterations of the loop. In this section you'll examine the break and continue commands that are used to control the execution of loops.
Recall that the while loop terminated when a particular condition was met. This happened when the task of the while loop completed. If you make a mistake in specifying the termination condition of a while loop, it can continue forever. For example, say you forgot to specify the $ before the x in the test expression:
x=0
while [ x -lt 10 ]
do
echo $x
x=`expr $x + 1`
done
This loop would continue to display numbers forever. ...
Read now
Unlock full access