LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2011, 03:10 AM   #1
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Rep: Reputation: 0
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
 
Old 02-09-2011, 04:24 AM   #2
appilu
Member
 
Registered: Jan 2011
Distribution: RedHat,Debian-Ubuntu,Fedora
Posts: 73

Rep: Reputation: 8
HI,
I thnk your condition check is done once on last,so only it is staying in loop till last condition
 
Old 02-09-2011, 04:47 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,643

Rep: Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961
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.
 
Old 02-09-2011, 10:47 AM   #4
dnoob
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
thats a big 10 4
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 04:49 PM
for loop or while loop to read the fields of a file.. visitnag Linux - Newbie 10 09-02-2010 09:47 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 04:50 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 03:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration