|
This is the course which dumps everything which you should know into one big chunk for you to absorb. Don't look for anything specific though. Nothing is specific around here. (Don't skip this course though, even though it might seem disorganised, it's still pretty important.) How do you comment out code? Surprisingly, commenting out code is simple. Just enclose your comments between the curly braces, { and } . Comments start from the left curly brace, all the way to the next right curly brace, regardless of line breaks, whitespace, or otherwise. What are units? As you know, a Pascal program is split up into several sections before the main code. Besides 'const' and 'var', you can also use 'uses', which adds a unit into a program. For example: uses
Crt, Graph;
What are units then? They are somewhat like plug-ins for the language. You can add
them to your program to provide new procedures, functions, and data. And because
you can write your own units, this means that you can share your most favourite
procedures or functions across several programs. Pascal comes with a few standard
units though. They are:
The most commonly used units would be Crt, Dos, and Graph. The System unit is automatically loaded and provides all the basic commands like Writeln, and Write which you'll see later. What are some of the more common commands? If you need to print stuff out, there's nothing like Writeln and Write. As you might have guessed, the difference is that Writeln goes on to the next line after printing. To print stuff out, just pass it what you want it to print, separated by commas: Writeln('Hello from Planet ', PlanetName, '!');
Write('Hee-hee!');
Also notice that both string and character literals in Pascal use single quotes.
No double quotes are used in Pascal. (Weird, considering that compilation would be
easier if they were.)
What if you want to collect input? Well, Readln and Readkey will do the job. Readln reads the entire line typed by the user, while Readkey just reads a key. Note that Readkey is in the Crt unit and it must be added to 'uses' to work. Their implementations are different: Readln makes you pass the variable to contain the value as a parameter. Readkey is a function which returns a character. var
s: string;
c: char;
begin
Readln(s);
c = Readkey;
end;
That's all for Readln and Readkey for now. So, you know how to read and write, what
more could you possibly want to know? What? Clear the screen? Okay...
If things get too foggy, or there's a haze, or your monitor is too cluttered with nonsense from some other rogue program. Load in Crt and execute this devious command: Clrscr;Nothing better than watching a screenful of text just disappear like that, isn't it? Press Alt-F5 to enjoy the emptiness. What's the semicolon for? In case you're unfamiliar with why a semicolon is at the end of every line, it's there mainly because the compiler needs to know where the end of each statemnt is. This is necessary because statements might spill over multiple lines, and the semicolon acts as a marker. If you're puzzled about where to place semicolons and where not to, well, we can only say it comes with experience. Program in Pascal long enough and you'll find your semicolons appearing automatically. (By the way, two oddities about the semicolon: Firstly, the last line of of any begin...end block doesn't need a semicolon. Secondly, the last end in a program has to end with a full stop. This full stop signifies that the finishing point of the program.) The End Is Here Go on, move to Intermediate. Everything's done. There's nothing more. Well, that's unless you're still confused, which if you are, you should go on to Pascal Programming for Programming Illiterates for a full refresher. Otherwise, bon voyage! |
||||||||||