Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Help with 'while' loop matching against 2 values

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
pmosinskis
Asked:
pmosinskis
1 Solution
 
TintinCommented:
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
 
tomcleggCommented:
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
 
pmosinskisAuthor Commented:
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
 
SpideyModCommented:
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
 
MindphaserCommented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now