While loop

While loop is another useful loop occurs in all programming languages. First checks whether the condition is true, if so, made ​​a list of commands contained within the loop when the condition becomes false the loop is completed.

Syntax:

while [condition], do
   order
done

example:



#!/bin/bash
x=1;
while [ $x - le 10] ; do
   echo "The inscription appears: $x"
   x=$ [x + 1]
done

Condition is checked whether the variable xo initial value 1 is less than or equal to 10, the condition is true so that the commands are executed inside the loop: echo "The inscription appears at once: $x" and x=$[x + 1], which increases the value of the variable x about one. When the value of x exceeds 10, the execution of the loop is broken.