Looping statements in Linux

Looping are a powerful programming tool that are used to execute a set of commands repeatedly. The various looping statement are:

While loop

The while statement has the general form is:

While command-list 1
do
command-list 2
done

The command in command-list are executed; and if the exit status of the last command in that list is 0 (zero). The command in command-list 2 are executed. The sequence is repeated as long as the exit status of command-list 1 is 0 (zero).

For loop

The For loop notation has the general form is:

for var in list-if-words
do
commands
done

Commands is a sequence of one or more commands separated by a newline or; (semicolon). The reserved words do and done must be preceded by a newline or ; (semicolon).
Small loops can be written in a single line e.g. for var in list; do commands; done.

Until loop

The Until statement has the general forms is:

Until command-list 1
do
command-list 2
done

This is identical in function to the while command except that the loop is executed as long as the exit status of command-list is no-zero.
The exit status of a While/Until command is the exit status of the list command executed in command-list 2. If on such command list is executed, a While/ Until has an exit status of 0 (zero).