Chapter Syllabus
11.1 Arithmetic and Logic Operations
11.2 The while-do-done Loop
11.3 The until-do-done Loop
11.4 The for-do-done Loop
11.5 Breaking a Loop
11.6 Text Processing
Loops are used to perform an operation repeatedly until a condition becomes true or false. The test or let command is used to check the condition every time a repetition is made. All loop structures used in shell programming start with a keyword. The block of commands that is executed repeatedly is enclosed by the do-done keywords.
There are three basic types of loops. The first one is the for-do-done loop, which is used to execute a block of commands for a fixed number of times. The while-do-done loop checks for a condition and goes on executing a block of commands until that condition becomes false. The until-do-done loop repeats the execution of a block of commands until a condition becomes true. As soon as the condition becomes true, the loop terminates.
All of these loops are controlled by a variable known as the control variable. This variable gets a new value on every repetition of the loop. The let command is also used to make arithmetic, logic, and assignment operations inside the loops and to change the value of the control variable.
In this chapter, we will start with arithmetic and logic operations performed with the let command. The three loops will be discussed one-by-one. You will find the general syntax of each loop as well as a flow diagram. In the end, you will find some text processing examples and their use in loops.
Top |