HOME - - - - - - - - - Other material for programmers - - - - - - - - - Pascal Tutorials Table of Contents

Pascal Programming: First Steps, using Pascalite



N.B. This version of the first tutorial is tailored to the needs of readers who wish to learn about Pascal using the free Pascalite compiler and development environment.

Alternate versions of the tutorial are available tailored to the needs of others-

First steps with Pascal using the opensource FPC Pascal, aka FPK, aka "Free Pascal".

First steps with Pascal using Borland's Turbo Pascal, version 5.5, which is available for free download.



"Let's start at the very beginning...."

A ten-year-old working at home without help should be writing programs in Pascal, using Pascalite, after applying him or herself to the following... if I've done it right! For those of you who are NOT new to programming, may I ask you to skim through the "Level One" material anyway? There are some things you might find useful. I'm working on a Windows 98 machine. Windows 95 or the higher Windows should also work.

Everyone: Please make use of the good helpfiles that come with your Pascal! My tutorials are not meant to supplant those, merely to take you through what is there in an easy (I hope) sequence. A useful feature of Pascalite is that if you are editing your program, and you want to look up say, GetTime, in the compiler's helpfile: Just type "GetTime" (without the quotes), leave the cursor in the word, or just past it, press F1, and, hey presto, you'll be taken to the right entry in the help file!

"First catch your rabbit", in this case download and install the free software. I know: Its a hassle. It will take disc space. There are risks. Well, Pascalite installed for me with minimal hassle. As the man said... Try it, you (may) like it. And at least in this case, you have some reassurance that it "should" work.

Launch Pascalit.exe. You get a simple window with a menu. Click on File|New|Empty.

A blank page will result. On it enter the following:

program first;
begin
write(lcd,'Hi');
end.

In a moment, we'll make something happen. But before we do, let's save your typing.

The machine will invoke the save, anyway, even if you don't. The saving is like any other Windows saving, if you are already familiar with it. But I'll take you through things, just in case:

Click File|Save. This will actually bring up the "Save As" dialog box, because this is the first time you are saving the program you've just typed in. You could just enter "My Program" in the file name box and click "ok", but I'm going to suggest a slight improvement.

You are likely to be in the folder (directory) into which you installed Pascalite. What you see may vary slightly from what I saw, but the first three files I had were Adv_text.pas, Average.pas and Avgarray.pas. I would suggest for the files you create making a folder within that folder. In Windows 98, you can simply put the mouse pointer among the file names and right click. Then select "New", "Folder", and give it some suitable name, e.g. "My Pascalite Prgms". There's also an icon you can use for creating a new folder: A folder with a radiating star on the upper right corner.

Double click on the new folder, once created, to move into that folder. Assign a name for the file, I'd suggest "First", or "PLT1ap". (PascalLite Tutorial 1ap, which is the name of the web page you are reading.) Click "Save".

(A little aside for people very new to Windows. The following is true not only for Pascalite, but for most Windows applications. If you've started something from scratch, i.e. by using File|New, then the first time you save it, you get the "Save As" dialog, as I've already said. From that point on, if you use File|Save, your work is simply saved where ever, and under whatever name you specified during the first save. The previous version of your work is over-written. Also, when you load something pre-existing, then doing File|Save will again simply replace the previous version. If you have been working on something, and you don't want to destroy the previous version, then use File|Save As, and change the name used for saving what you have.)

So... you've typed in the little program I gave you. You've saved your typing.

Now click Tools|Simulate Program (or just press F2.. equivalent.) You may well get an error message, in which case a line of your program will be displayed in red. Find the error, fix it, maybe re-save, and try Tools|Simulate Program again. (The line in red is where the compiler noticed the problem. It is not uncommon for the underlying flaw to be earlier in the program. Often you have failed to end the previous line with a semicolon (;). Not every line ends with a semicolon, but they are easily forgotten.)

Don't be alarmed if it seems that nothing has happened. First you need to tell the program to run. Isn't that what "Tools|Simulate Program" said??? Not exactly... that only switches you out of the program editor into the simulation environment. Once there, you need to click on the green, right pointing, triangle on the simulator toolbar to run the program in the simulator. Even when you do that, our little program doesn't appear to do much. Look carefully at the "Simulator" panel that opens when the system is in simulation mode. Near the bottom, on the left, is a simulated LCD display with the following text: "Pascalite II Pro / (c) Control Plus / V2.50 / 2000". Watch the space just after the "2000" when you click the green "Run Program" triangle- you should see "Hi" appear briefly. That's your program running! (The LCD simulation starts with the copyright message, and after your program has run, the panel clears itself and restores the message... that's why the "Hi" appears so briefly. Don't worry... we can make the computer do things our way!

Just one last little flourish to finish off this first tutorial. You won't finish a real program in one go. Part of learning to program is learning to build something up by degrees. Typically, after typing a start, and clicking Tools|Simulate Program, you'll have to leave the simulator, which will send you back to the editing environment. All you need to do to leave the simulator is click on the red X on the simulator toolbar. Adding a second write line, e.g. "write(lcd,'Bye');" Click Tools|Simulate Program again, see your new masterpiece in action (or fix the typos!) and then pat yourself on the back... you're a programmer.

Just one last little flourish to finish off this first tutorial. You won't finish a real program in one go. Part of learning to program is learning to build something up by degrees. Typically, after typing a start, and clicking Tools|Simulate Program, you'll have to leave the simulator, which will send you back to the editing environment. All you need to do to leave the simulator is click on the red X on the simulator toolbar. Adding a second write line, specifically write(lcd,'Bye'); Click Tools|Simulate Program again, see your new masterpiece in action (or fix the typos!) and cheer... you're a programmer!


Oh yes... I said I'd take you through the program....

Every Pascal program begins with the word "program". After that, you supply a name; I chose "First" in this case. (PLT1a would have been better, but might have confused you at that stage.) And then the line is finished with a semicolon. You get a lot of semicolons in Pascal. More on them another time.

Next in our simple first program came the word "begin". For every "begin" there is an "end". You can have many begin/end blocks, and they always nest. Leaving out the rest, a complex program might look like.....

begin
  begin
    begin
    end;
  end;
  begin
    begin
      begin
      end;
      begin
      end;
    end;
  end;
end.

Did I scare you? I hope not... I wanted you to look forward to the excitement of a really sophisticated project! Anyway. Begins are always paired with ends, as I said. You do NOT put a semicolon after the begin (unusual), but you do put one after the end... usually. (I'll discuss the exceptions another time.) After the final end in a program, you put a period (full stop) instead of the semi-colon.

write and writeln are words built into all the Pascals we've been discussing. (A rough equivalent for Delphi, by the way, is "showmessage", e.g. showmessage('Hi');).

"lcd" says where we want to write to... there aren't many choices. More on them another time. (It is left out for the FPC and TP versions of the program, because they will write to the correct places without help.)

Note that we put apostrophes around the text we want written, rather than the quotation marks we would use in everyday English.

And we've already covered the "end.", so we're almost done! In a moment, you can go give yourself a treat.

Or return to the index of Pascal tutorials for another one!

One little thing before we go. You see the way things are indented in the big block of begins/ ends above? You can move text around to set it out any way that helps you see what is going on. Pascal is unfussy about spaces and new-lines. Guess what? "More on this later." (Again!)


Please also note that I have two other sites, and that the following search will not include them. They have their own search buttons.

My Sheepdog Guides site.
My Arunet site.

Go to the sites above, and use their search buttons if you want to search them.
To search this site....

Search this site or the web powered by FreeFind

Site search Web search
The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

You can also search this site without using forms.
Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.


Want a site hosted, or email? You can also help me if you sign up via this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their customers. The Google advertisers pay me. I know nothing about them or their services, of course.)



Valid HTML 4.01 Transitional Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Also, I have some of my pages' traffic monitored for me by eXTReMe tracker. They offer a free tracker. If you want to try one, check out their site. Why do I mention the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or write this page's editor, Tom Boyd

....... P a g e . . . E n d s .....