HOME - - - - - - - - - Other material for programmers - - - - - - - - -

Pascalite Programming: First Steps



This is a page which is currently being neglected by the site editor.

Go to the Pascalite Tutorial Table of Contents and follow a link from there for more current material.







N.B. This version of the first tutorial is tailored to the needs of someone who wishes to learn about Pascal WITHOUT a copy of the free Pascalite compiler and development environment installed on his/ her computer. If this is NOT you, then click here for an alternate version of this tutorial. I recommend setting up the Pascalite compiler, and using the other tutorial, but you don't need to.

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

A ten-year-old working at home without help should be writing Pascal, using the 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, can I ask you to skim through the "Level One" material anyway? There are some things you might find useful.

Everyone: Please make use the help files that come with compilers. My tutorials are not meant to supplant them, merely to get you productive relatively painlessly.

A useful feature of Pascalite and Delphi: 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! (Ctrl-F1 for Delphi.)

In whatever Pascal you may be using, you start by entering "sourcecode" into the computer. (Use Pascalite, and the other "Start Here" tutorial, and I'll tell you the details specific to that environment!)

As a first example, let's use....
program first;
begin
writeln('Hi');
end.
As with any computer work, save what you've done often. Saving sourcecode, in all environments I've seen, is like saving any other text....

Click File|Save. This will probably 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.

Make a folder (directory) in My Documents called Pascal. Within that, make a folder called Sheepdog Tutorials. Within that, make a folder called PLT1a.

Be sure you've moved into the PLT1a folder. Save the sourcecode listed above in that folder. Save it as PLT1a.pas. (PascalLite Tutorial 1a, which is the name of the web page you are reading. (Well.. actually you are reading PLT1aAlt, the Alternative version of PLT1a... but ignore the Alt part!). (Your editor may take care of the .pas part for you.) Each lesson is on a web page called PLT+a digit+a letter. The digit indicates the tutorial's level, the letter is to tell the different tutorials within one level apart.

(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 whereever, 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 you tell your compiler to compile and run it, i.e. turn it into something the computer "understands" and do it. You may well get an error message. Find the error, fix it, re-save the source-code, and try to compile and run. (Different environments will help you in different ways, but most will present a line of code which may contain the error. 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. You need to issue a second command to make the program run. When you run the program you should see "Hi" appear briefly. That's what your program does! Outputs "Hi"!

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. Add a second write line, e.g. "writeln('Bye');" Compile and run the program again, see your new masterpiece in action (or fix the typos!) and then pat yourself on the back... 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.

"writeln" is a word built into Pascal.
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 done. Go give yourself a treat.

Or return to the index of tutorials for another one!

To search THIS site.... (Go to the sites above, and use their search buttons if you want to search them.)...or, use...
Click this to search this site without using forms.
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"....

Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.
My site at Arunet.
My oldest site. (It's at Compuserve).
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.

Link to editor's (Arunet) homepage
How to email or write this page's editor, Tom Boyd