LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-07-2004, 10:57 AM   #1
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Rep: Reputation: 30
Simple while loop problem (newbie question)


Hi all, this guy isn't working, and from what I know it seems like it's correct.

If anyone could troubleshoot this guy, I'd really appreciate it. Just a basic Yes/No loop that if the answer isn't "Yes" or "No" tells them to answer as such.

Thanks!

Code:
print "Would you like to update the tree (recommended) [Yes/No]?" ;
$update = <STDIN>;
chomp ($update);

$i = 0;                                         # Set count

while $i = 0; {
if ($update eq "Yes") {
    $i = $i + 1;
    system ("clear");
    print "Updating CVS tree, standby...\n";
    qx (cvs update -A);
    print "Finished. Hit Enter to continue.\n";
    $_ = <STDIN>;

} elsif ($update eq "No") {
    $i = $i + 1;
    print "\nContinuing without update, please hit Enter to continue.\n";
    $_ = <STDIN>;                                # Blank Variable for CR
                                                 
} else {
    print "Please answer Yes or No.\n";
    chomp ($update);
    $i = 0;
}
}
 
Old 09-07-2004, 11:12 AM   #2
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Original Poster
Rep: Reputation: 30
Got it, couple of syntax things.
 
Old 09-07-2004, 11:14 AM   #3
bestofmed
Member
 
Registered: Jul 2004
Location: Jemna, Tunisia
Posts: 46

Rep: Reputation: 15
1-I haven't a big knowledge in Perl but I think that the while condition should be in parentheses.
2-I think that that the comparison operator is '==`not one '=`(this one is for assignment).

Just try this


Code:
print "Would you like to update the tree (recommended) [Yes/No]?" ;
$update = <STDIN>;
chomp ($update);

$i = 0;                                         # Set count

while ($i == 0) {        #as you see it's == not =
if ($update eq "Yes") {
    $i = $i + 1;
    system ("clear");
    print "Updating CVS tree, standby...\n";
    qx (cvs update -A);
    print "Finished. Hit Enter to continue.\n";
    $_ = <STDIN>;

} elsif ($update eq "No") {
    $i = $i + 1;
    print "\nContinuing without update, please hit Enter to continue.\n";
    $_ = <STDIN>;                                # Blank Variable for CR
                                                 
} else {
    print "Please answer Yes or No.\n";
    chomp ($update);
    $i = 0;
}
}
Give it a try it shall work.

GOOD Luck
 
Old 09-07-2004, 12:00 PM   #4
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Original Poster
Rep: Reputation: 30
double-equals did the job. Thanks man!
 
  


Reply



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
Problem with simple shell script for loop abefroman Programming 2 10-25-2005 08:26 PM
Simple newbie question - how to... mazzo Linux - Wireless Networking 4 09-02-2004 03:34 PM
simple newbie question naijaguy Red Hat 1 08-11-2004 10:55 PM
Simple newbie question izrahi Linux - Newbie 1 08-11-2004 05:07 PM
newbie python question: doing more than one thing in a for loop SerfurJ Programming 1 03-18-2004 10:14 AM

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

All times are GMT -5. The time now is 08:13 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
Open Source Consulting | Domain Registration