11.3 The until-do-done Loop

   

11.3 The until-do-done Loop

The until-do-done loop is like the while-do-done loop. The only difference is that it tests the condition and goes on executing as long as the condition remains false. It terminates execution as soon as the condition becomes true. The general syntax of this loop is:

 until condition do    command block done 

The flow diagram of the until-do-done loop is shown in Figure 11-2.

Figure 11-2. The until-do-done loop.

graphics/11fig02.gif

As you may have noticed, the only difference between Figure 11-1 and Figure 11-2 is that the "True" and "False" positions have been interchanged. Here is script-22 , which has the same result as script-20 but was implemented using an until-do-done loop.

 #!/usr/bin/sh echo "The until loop example" echo VAR1=1 until (( VAR1 > 100 )) do    echo "Value of the variable is : $VAR1"    ((VAR1 = VAR1 * 2)) done echo echo "The loop execution is finished" 

   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net