Home
Intro
LC
ACR
About

Day 2 - Elements of Pascal

-=-=-=-=-=-=-=-=-=-=-

What you are going to learn today:

  • How do you start up Turbo Pascal
  • Your first Pascal program
  • And an analysis of each element in your program

-=-=-=-=-=-=-=-=-=-=-

Today, you're going to write your first Pascal program, and you're going to analyse it. No, forget those images of Biology class, you're just going to look through the dissection part briefly.

Starting Up Turbo Pascal

Ahhhh, this is easy. First, I presume you've already installed Turbo Pascal, right? Now just follow these easy to remember directions:
  1. Go to the directory where you installed Turbo Pascal (e.g. cd tp)
  2. Go to the bin subdirectory (e.g. cd bin)
  3. Type turbo to start up Turbo Pascal
In case you're wondering about what bin means, well, it means that whatever goes there should be consigned to the bin, or maybe some other form of mild destruction. Well, actually, that was just a joke. The bin directory actually means binary, and you shouldn't fool around with binary stuff, right? That directory contains all the program files, and you could really foul up there.
Now, just wait for a moment, and Turbo Pascal would appear with all its glory on your screen, filling it up with its large, grey, empty desktop. If this is its first startup, or you had quit it with an editor window open the last time you ran it, a new window would appear on your screen.
Well, what if it doesn't? Then just follow the instructions, just follow the instructions... This, is clicking on the File menu.
  1. Go to the File menu. (Click on the word "File")
  2. Select New from the pop-up menu that appears
Poof! A brand new window appears for you. Now, you can go on to do your magic, to type your very first program in Pascal...

Your very first Pascal program

The program you're about to type is only one method to implement the many techniques in programming. The user is invited to make his or her own changes to the program code to fit the situation. So here goes.

Type

1: program FirstProg;
2:
3:   begin
4:     { I always wanted to do this. }
5:     Writeln('Hel-lo nurse... I mean, World!');
6:   end.

Run

(To run, go to the Run menu and select Run. To see the output, go to the Debug menu and select User Screen. Don't worry, we'll explain it later.)

Hel-lo nurse... I mean, World!

Analyse

Now, that wasn't too difficult! Let's analyse the program line by line.

  • Line 1 - this is just a line declaring the program to be named FirstProg. In case you're wondering, this line is for humans to read, not for the compiler. See the semicolon after the name FirstProg? It's very special. You'll see why later.
  • Line 3 - this tells the compiler that you're beginning a block of code for it to read. The real code comes next.
  • Line 4 - this line is in curly brackets, signalling to the compiler that this is just a comment and should be ignored.
  • Line 5 - Now, this is the line that makes the magic. Catch the command at the beginning, Writeln? After that, comes a bracket and the line that gets printed follows behind with a closing bracket. See the semicolon again? We'll explain that very soon...
  • Line 6 - this tells the compiler that it is the end of the code block and it can stop reading code now. Notice that the semicolon is replaced by a full stop? Ahhh, food for thought.

The Program Listing

Now, let's see how this Pascal program really works. After Line 3 which starts the block of code, we have Line 4, which is a comment, telling us that "I always wanted to do this". The compiler ignores this line completely, giving us a fighting chance to make our code readable for other humans. In fact, that's exactly what comments are used for. Neat, eh? Let's go on.
Now, in line 5, we have the line that does all the magic. But how does it work? Well, we used the Writeln command, and we passed it the string we wanted it to print. Through some technical mumbo-jumbo and a lot of praying, the string gets its way onto the screen. Isn't that nice? Well, I bet you know what line 6 is for then. Yes, it's for ending off the program. Right on.

Mr ; : 'Wow! I never knew I was that famous!'

But what about the semicolon? Well, here's how it works. Pascal states that you end every statement or any block of code with a semicolon. So, line 1, which is a statement, ends with a semicolon. Line 5 too. All the statements in this program end with a semicolon.
Then what about the last line? Well, you can say that a Pascal program is like a long, unwieldly sentence. You must of course end off with a full stop. So, it's the same with the very last block of code. You must put a full stop instead of a semicolon because it is the end of the program. Logical, isn't it?

End Of Day 2

Finito. That's it. Day 2 is done and over with. Now, get ready for Day 3, which marks the beginning of your marathon Pascal knowledge race. Ready? Well, take your time... This is meant to be a tutorial, remember? So get up. Day 3 is waiting for you.

-=-=-=-=-=-=-=-=-=-=-

HomeIntroLCACRAbout
Back to Class B

-=-=-=-=-=-=-=-=-=-=-

This page is ThinkQuest entry 11127.
email: tq97-11127@advanced.org