Step 1 of 5 · Reading · ~1 min
Learn
Basics
Pascal was designed in 1970 by Niklaus Wirth as a language for teaching structured programming. It dominated CS education in the 80s and 90s. Today Free Pascal (FPC) keeps the dialect alive and is what Judge0 uses.
program Hello;
begin
WriteLn('Hello, Pascal!');
end.
The shape of every Pascal program:
program Name;— declares the program (mostly for documentation)begin ... end.— the main block. Note the trailing.- Statements end with
;(separator, not terminator — the lastend.doesn't need a;) - Strings use single quotes only. Double quotes don't exist.
- Identifiers are case-insensitive:
WriteLn=writeln=WRITELN - Comments:
{ ... }or(* ... *)
Write and WriteLn
WriteLn prints its arguments and then moves to a new line. Write prints and stays put. Both take a comma-separated list of mixed values:
Write('a');
Write('b');
WriteLn('c'); { one line: abc }
WriteLn('n = ', 42); { n = 42 }
Nearly every exercise here expects one value per line, so WriteLn is the one you want.
The unterminated-string trap
Because a literal is delimited by ' on both ends, forgetting the closing quote does not run off into the next line the way it might elsewhere — FPC stops at the end of the line and reports:
main.pas(3,13) Fatal: String exceeds line
If you see String exceeds line, count the quotes on the line it names.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…