Did the user press ENTER or not?
Write('Hello World! Press [ENTER] to exit.');
If (Ch=#13) then exit
else Write('!! INPUT ERROR !!');
- Program is a file header - letting Modern Pascal know this is a program. In this case, named "First".
- uses informs Modern Pascal additional run-time libraries to load. In this case, the keyboard and display library "display".
- var is the keyword to inform Modern Pascal that CH is of type CHARACTER.
- Begin ... End. is the main code block - the instructions that produce this algorithm of this program.
Code Block Explanation
- ClrScr stands for "Clear Screen" and erases everything in the command prompt (console, terminal).
- Write displays everything between the apostrophes (known as a string).
- ReadKey makes the program wait until the user presses any key, and stores the KEY character in the variable CH.
- if ... then is a comparison. If the expression CH equals the ENTER CHARACTER then exit the current code block.
- else is what to do when #4 is not a true expression. In this case, we display !! INPUT ERROR !!.