Im a beginner and i got a problem with repeat until loop
I want to know what exactly is supposed to happen in this little program :
program looptest;
Uses Crt;
Var YN : String;
Begin
Writeln('Y(YES) or N(NO)?');
Repeat {repeat the code for at least one time}
YN := Readkey ;
If YN = 'y' then Halt; {Halt - exit}
If YN = 'n' then Writeln('Why not? Exiting...');
Delay(1800); { wait a second plus 800 milliseconds }
Until (YN = 'y') OR (YN = 'n');
End.
thanks very much...
Comments
: I want to know what exactly is supposed to happen in this little
: program :
:
: program looptest;
: Uses Crt;
: Var YN : String;
:
: Begin
: Writeln('Y(YES) or N(NO)?');
: Repeat {repeat the code for at least one time}
: YN := Readkey ;
: If YN = 'y' then Halt; {Halt - exit}
: If YN = 'n' then Writeln('Why not? Exiting...');
: Delay(1800); { wait a second plus 800 milliseconds }
: Until (YN = 'y') OR (YN = 'n');
: End.
:
: thanks very much...
:
[code]
program looptest;
Uses Crt;
Var YN : String;
Begin
Writeln('Y(YES) or N(NO)?');
Repeat {repeat the code for at least one time}
YN := Readkey ;
If YN = 'y' then Halt; {Halt - exit}
If YN = 'n' then Writeln('Why not? Exiting...');
Delay(1800); { wait a second plus 800 milliseconds }
Until (YN = 'y') OR (YN = 'n');
End.
[/code]
[blue]
The program goes through the loop repeatedly until you hit either a lower case 'y' or a lower case 'n'. If you hit 'y' the program ends immediately. If you hit 'n' the program prints 'Why not? Exiting...', exits the loop and terminates anyway. There is a 1.8 second delay each time through the loop.
The [b]Halt[/b] exits the program immediately without going through the delay at the bottom of the loop. The other exit encounters the [b]Delay[/b].
[b]Readkey[/b] will wait for you to hit a key and need not be followed by hitting the Enter key. If you do hit the Enter key it will be ignored.
[/blue]