Your First Program
Spinner = ['\','|','/','-'];
While Session.Connected do begin
// produces a spinning prompt until the terminal disconencts //
If (Count>3) then Count:=0;
- Program is a file header - letting Modern Pascal know this is a program. In this case, named "First".
- Const defines a variable that cannot be changed during execution.
- Var defines a variable used in this case as a counter from 0 to 4, used as 0 to 3.
- 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).
- While initiates a type of loop that will execute when the expression following it is true. In this case, the terminal is connected.
- do Begin starts a block of code that will execute while "Session is Connected".
- Write displays the spinner character following back #8 (backspace)... keeping the cursor in the same spot as the spinner.
- Yield(100) pauses execution for 100ms -- making your code CPU friend, and avoiding the spinner from spinning to fast.
- Inc(Count) increments (adds 1) to Count.
- If tests the expression following, if true then it resets Count back to zero.
- End tells the interpreter to return to the while statement and start at step #3 above.
- 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).