A Brief Introduction
Some of you out there might have forgotten those old programming concepts of
olden times. Well, here's a quick refresher over those confounded programming
concepts. (Such as variables, procedures, control flow, and so on...)
What programming is all about
Well, programming is about controlling the computer. And to control the
compiler we give it a program, which is a sequence of instructions. That's
why it's called programming. And how do you program? First, you use a language. Then
you get a compiler, then voila! You're a programmer! Pascal is an example of a
programming language, and the most popular compilers on the market for Pascal come
from Inprise. Visit their website to find out about Turbo Pascal or Delphi, if you
don't have them yet. Those are the compilers we'll be using throughout this
Remember, programming can be both a fun and painful hobby, depending on how you
view it. So, look on the bright side, and take it lightly. You're dealing with computers,
remember? So just sit back and enjoy the ride!
The different parts of programming
Now, even before we even get into Pascal, let's ask the question you've all been
waiting for: What is inside programming? Well, to answer this question, we'll try
to tell you the typical parts of every programming language, whether it's Pascal,
C++, or BASIC. We'll use this list as a guide later on.
Variables - storing values
Well, let's start off with variables. Remember those Algebra classes?
All programming language work on something called variables, which work the
same way algebra does (at least at first glance). Each variable has a name and
contains a value. For example, a variable can be named a, containing the
value 2. Thus you can say a plus a equals to 4. Easy, no?
To jump the gun a bit, let's discuss about how Pascal handles variables. In
Pascal, you would first declare a variable, then assign values
into it. An assignment is somewhat like the reverse of a maths statement. Like
other languages, you would have the variable name first, the assignment
operator, then the value to be assigned. We'll talk about the syntax
Constants - staying the same
Essentially, constants are what they are, constant. A constant just simply replaces
something else, like how some publications replace certain words with asterisks when
necessary. To give an example, let's say that we replace every appearance of the
word "lamb" with "head" to make the sentence "Mary had a little lamb" to become
"Mary had a little head". Thus, you could say that the word "head" was a constant
representing "lamb", with apologies to all lamb-lovers out there of course.
Control Flow - changing directions
When you run through a list of instructions, you normally go through them step by
step, but what if that's not the case? What if you are to press the red button when
a tone is heard and the green one when not? What if you are supposed to scream when
a meltdown occurs but shout when a fire starts? That's where control flow comes in
to change the course of the program. Control flow is necessary because you can't
expect everything to be like a set of instructions. Changes have to be made.
For example, you can say, "Jump off the building if it is on fire,
else continue typing your report." The statement above accomplishes something
a list of instructions just can't do - change the direction.
Procedures - sub-routines
When you need to do something again and again, or to process some information, the
programming mechanism you use is called a procedure. A procedure is something like
a fixed set of instructions which can be repeated again and again. For example, a
procedure may state, "Get the number of customers in the room and get the appropriate
number of chairs". Thus, this procedure can be used in a concert, or a party, or any
one of those lavish social occasions people never really care to go to. That's how a
Functions - sub-routines which return values
A function is just like a procedure, except that it returns a value. For instance,
we may have a procedure that accepts two numbers, one representing the number of
Godzillas there are on a street, the other representing the number of innocent
bystanders passing by, and calculates the average number of screams every 5 seconds.
This is called a function because it returns a value, which is the average number of
Comments - little notes
The final thing we have on our list are comments, which allow the programmer to add
notes to his code. This makes the code easier for other people to read, and easier
to change when debugging.
In the next few courses, we'll discuss these topics in depth. Of course, since
you should have some experience with programming at least, we won't go any further
than what we think you need. With that in mind, you can either go on, or select
any other course of your choice. Whatever it is, enjoy yourself!