I have this program which takes a array of words and asks user to type a sentence which has each of the word from the array:
@words = qw(Hi world thanks);
foreach $word (@words)
{
print "Enter a line with word:$word\n";
chomp($input = <STDIN>);
if($input=~/$word/i)
{
print "Great\n";
} else {
print "Incorrect. Type a line containing $word\n";
}
}
If the user types a input with the word, it works fine. But if he doesn’t It only prints the error message and moves to the next word. I want it it prompt the user to re-enter inputs for the same word. But how ? I tried next it did not work.
You can use a
redoin this case to restart the current iteration.A less-recommended alternative is to use a
goto: