Sem 3‎ > ‎OS (Unix) LAB‎ > ‎

D9: Looping

posted Oct 9, 2011, 8:18 AM by Neil Mathew   [ updated Oct 9, 2011, 8:18 AM ]

For Loop


Syntax:

for { <variable_name> } in { <list of variable> }
  do
          <commands>
  done




Example:

echo "Using for loop method... "
for i in 1 2 3 4 5 6 7 8 9 10
do
  echo -n "$i "
done
echo ""






While Loop

Syntax:

  while [ <condition> ]
           do
                 <command1>
                 <command2>
                 
           done




Example: 

while [ $n -gt 0 ]
do

f=`expr $f \* $n`
n=`expr $n - 1`
done



Comments