LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   broken do while loop (https://www.linuxquestions.org/questions/programming-9/broken-do-while-loop-861552/)

dnoob 02-09-2011 02:10 AM

broken do while loop
 
i can not figure out why my program does not terminate if i type n when i read loop unless it is the last if statement in my program ?


while [ "$loop" = y ] ; do

echo "what does baket mean: " ; read word
if [ "$word" = why ]
then
echo "Good job!"
else
echo "Not correct"

echo "Do you want to continue (y) (n)" ; read loop
fi
clear

echo "what does araw araw mean: " ; read word
if [ "$word" = daily ]
then
echo "Good job!"
else
echo "Not correct"
fi

echo "Do you want to continue (y) (n)" ; read loop
clear

echo "what does maganda mean: " ; read word
if [ "$word" = pretty ]
then
echo "Good job!"
else
echo "Not correct"
fi

echo "Do you want to continue (y) (n)" ; read loop
clear

done

appilu 02-09-2011 03:24 AM

HI,
I thnk your condition check is done once on last,so only it is staying in loop till last condition

grail 02-09-2011 03:47 AM

Maybe you need to follow your code closer. The while loop will process all intermediate steps until it hits one of the following (in general):

break
continue
exit

As none of these words appear prior to the closing done for the while loop then the only time your response is read is after the done statement.

dnoob 02-09-2011 09:47 AM

thats a big 10 4


All times are GMT -5. The time now is 01:31 AM.