Bash programming/Loops

Loops are an essential part to many programming languages, and this holds true for Bash scripting as well.

For Loop
A simple way to incorporate a loop into a Bash script would look like this:

This loop would take the input from the user and separate it by the IFS (Internal File Separator). It would then the variable i to each value, and execute the commands inside the loop. In this case, the only command inside the loop is the echo command.

By default, the IFS contains the space character and newline character, so if the user were to enter "Jim Joe John", the program would output: Hi there Jim, pleased to meet you. Hi there Joe, pleased to meet you. Hi there John, pleased to meet you.

Another example with a sequence of numbers using improved brace expansion operator, improved in Bash version 3.0 on July 2004 :

While Loop
On systems without support for brace expansion, sequential numbers may be printed out using the  command, but it creates new lines which may be undesirable. A while loop can be used to print a sequence of numbers in a single line:

For more information you can check:
 * Bash Guide for Beginners: The while loop
 * Advanced Bash-Scripting Guide: Chapter 11. Loops and Branches
 * POSIX standard

While Loop reading lines / Iterating on lines
See also how to embed newlines in a string: https://superuser.com/a/284226