CodeRunner MPL Documentation

Your First Program

Program First;

   Spinner = ['\','|','/','-'];


   Session.Write('Hello World!');
   While Session.Connected do begin
   // produces a spinning prompt until the terminal disconencts //
      If (Count>3) then Count:=0;

Source Explanation

  1. Program is a file header - letting Modern Pascal know this is a program. In this case, named "First".
  2. Const defines a variable that cannot be changed during execution.
  3. Var defines a variable used in this case as a counter from 0 to 4, used as 0 to 3.
  4. Begin ... End. is the main code block - the instructions that produce this algorithm of this program.

Code Block Explanation

  1. ClrScr stands for "Clear Screen" and erases everything in the command prompt (console, terminal).
  2. Write displays everything between the apostrophes (known as a string).
  3. While initiates a type of loop that will execute when the expression following it is true. In this case, the terminal is connected.
  4. do Begin starts a block of code that will execute while "Session is Connected".
  5. Write displays the spinner character following back #8 (backspace)... keeping the cursor in the same spot as the spinner.
  6. Yield(100) pauses execution for 100ms -- making your code CPU friend, and avoiding the spinner from spinning to fast.
  7. Inc(Count) increments (adds 1) to Count.
  8. If tests the expression following, if true then it resets Count back to zero.
  9. End tells the interpreter to return to the while statement and start at step #3 above.
  10. Otherwise, step #3 (if false) will jump down to the next statement, End. which denotes the end of the script.
    At which point, the interpreter terminates and CoeRunner releases that instance on the socket and resumes waiting
    for the next connection (which is what it does while each script is executing).