Click to See Complete Forum and Search --> : simple loop question?


jwisneski2003
09-18-2005, 01:49 PM
hello all,
how can i get this code to ask for the correct input 3 times?

thanks john


print "enter a password";
while (<>) {
chop;
if ($_ ne 'password'){
print "try again";

} else {
print "success you win";
exit;
}
}

Ultimater
09-18-2005, 02:03 PM
my $passwordTrys=0;
print "enter a password";
while (<>) {
chop;
if ($_ ne 'password'){
print "try again";
$passwordTrys++;
if($passwordTrys ge 3){last;}
} else {
print "success you win";
exit;
}
}

jwisneski2003
09-19-2005, 08:32 AM
hello ultimator,

thanks i knew it was simple, its these curly braces that are driving me crazy..thanks again john