What are the differences between a for loop and a while loop in shell scripting? Provide Examples. -- UNIX/LINUX
Both are used to iterate over the statements but the difference is for loop will have everything at one place like initilizatio and condition and increment/decrement where as while loop all three things will be at different places
we use while loop when we are not sure about the count. we will use while loop to read data from database or file
we use for loop to process the arrays and list
example:
x=0
while [ $x -lt 5 ]
do
echo $x
x=`expr $x + 1`
done
For Loop:
for var in 0 1 2 3
do
echo $var
done
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
Please Like and Support me as it helps me a lot
Get Answers For Free
Most questions answered within 1 hours.