Bucle realizate cu instrucţiunea until

83

            Un exemplu de program care utilizează instrucţiunea until este următorul (tst9.pl):

#!/usr/local/bin/perl
print ("What is 17 plus 26?\n");
$correct_answer = 43;     # the correct answer
$input_answer = <STDIN>;
chop ($input_answer);
until ($input_answer == $correct_answer){
    
print ("Wrong! Keep trying!\n");
     $input_answer = <STDIN>;
     chop ($input_answer);
}
print ("You've got it!\n");

După o rulare particulară a acestui program consola text poate arăta astfel.

What is 17 plus 26?
23
Wrong! Keep trying!
32
Wrong! Keep trying!
43
You've got it!

Cornel Mironel Niculae, 2003-2004

13-Nov-2009