Loops
06. LOOPS
There are three
types of loops: while, until and for. The while loop is followed by a command
or an expression enclosed in square brackets, a do keyword, a block of
statements, and terminated with the done keyword. As long as the expression is
true, the body of statements between do and done will be executed.
The until loop is
just like the while loop, except the body of the loop will be executed as long
as the expression is false.
The for loop used
to iterate through a list of words, processing a word and then shifting it off,
to process the next word. When all words have been shifted from the list, it
ends. The for loop is followed by a variable name, the in keyword, and a list of
words then a block of statements, and terminates with the done keyword.
The loop control
commands are break and continue.
EXAMPLE
while command do block of statements done ------------ |
for variable in word1 word2 word3 ... do
block of statements
done |
while [ expression ] do block of statements done until command
do block of statements
done
|
until control command do commands done |
07. Break Statement :
This command is used to
jump out of the loop instantly, without waiting to get the control command.
Comments
Post a Comment