?
Solved

Help with 'while' loop matching against 2 values

Posted on 2003-02-27
5
Medium Priority
?
151 Views
Last Modified: 2010-03-05
Hi,

Every time I run this, it never breaks out of the loop. What am I missing here? I want to restrict the loop so that the user has to enter 1 or 2 before continuing.


while (($pwcase != 1) || ($pwcase != 2)) {
     print "Type the number of the password option you want:\n";
     print "[1] Uppercase password\n[2] Lowercase password\n";
     print "Choose:";
     $pwcase = <STDIN>;
     chomp ($pwcase);
}

Thanks,
Pete
0
Comment
Question by:pmosinskis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 100 total points
ID: 8039463
A better way to write it is:

#!/usr/bin/perl
while (1) {
    print "Type the number of the password option you want:\n";
    print "[1] Uppercase password\n[2] Lowercase password\n";
    print "Choose:";
    $pwcase = <STDIN>;
    chomp $pwcase;
    last if ($pwcase == 1 or $pwcase == 2);
}
0
 
LVL 1

Expert Comment

by:tomclegg
ID: 8040404
pmosinskis, your bug is that you typed || when you meant &&.

You can also add "$pwcase = 0;" before the loop, to fix the other bug that Tintin fixed.
0
 
LVL 2

Author Comment

by:pmosinskis
ID: 8044544
Thank you both tomclegg & Tintin. Because both your answers are right, I will submit to split points.
Thank you both for your excellent help!!
0
 

Expert Comment

by:SpideyMod
ID: 8044851
pmosinskis,
I have reduced the question value for this question to half so you may accept one of the expert's answers and issue a "points for expertname re 20533086" question for the other expert (replace expertname with the name of the other expert).  When you have created the new question for the other expert, return to this question and post the link to the new question so the expert know where to find it.  Do not close out the split request in community support until you have finished all the steps in the split.  Thanks.


SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 8153011
Force accepted

** Mindphaser - Community Support Moderator **

tomclegg , there is a separate question with points for your help in
 http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20553631.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question