• Keine Ergebnisse gefunden

Did you know that computers can show up a basic difference between people's learning habits? Many people who sit down at a computer which they have never see before will start right in pressing keys. On the other hand, some people will wait for instructions before touching anything. Even with instructions, it will take these people quite a while before they are comfortable with a computer, while the first type of people were never really uncomfortable in the first place.

Now, the reason I am bringing this matter up here is not to scare you, or make you feel as though "my goodness, this is too difficult." It is because I want to encourage you to sit down and press computer keys, especially if you are the type who is over cautious about such things. This is the way you will learn about your computer most quickly. By the way, today's computers are designed so that with appropriate precautions (such as making backup copies of all your diskettes), it is highly unlikely that you will cause any permanent damage by typing on the keyboard.

You see, a computer, unlike your mind, does not think in any real sense. At its most fundamental level it thinks in terms of "on/off", or "yes/no", but never "semi-on" or "maybe". It will only follow its instructions (whether they make sense, or not) until its electrical power goes off.

DUMB

MACHINE

aYB

Also you should remember that as a human being you have ultimate control over your computer: you tell it what to do and when to do it. You do this by pressing keys and giving it immediate instructions, or by pressing keys for instructions which the machine will remember and then execute later on. (By the way, the second example is what we mean when we talk about writing a computer program).

When we work with computers we have to get into two habits.

One: we always (not sometimes) must be consistent in how we tell the computerto do something. (In other words, the computer is very inflexible.) Two: If we give the computer the wrong information to work with, it won't know the difference, and will try to proceed as usual, causing erroneous and sometimes interest-ing results. This is what we will call "Garbage in, Garbage out."

I n other words, with computers, as with no other part of life, it will always benefit you to take the time to first "Think It Through"

-to pretty well know what you are going to do before you start, and second: "00 It Right The First Time"-so you won't have to do it again.

Well, what do you say we just try a program? Our first program doesn't do much, and you may not understand everything about it right away -but then even driving a car is not second nature at first. If you need to, read the chapteron "Getting Started" in your Reference Manual to show you how to write and run a TURBO Pascal program.

By the way, I have written all the special words TURBO Pascal recognizes as instructions in bold letters. This makes it particu-larly easy to read a program and make sense out of it. By the way, these special words are called reserved words.

To get started right away, do the following steps:

1. Start your TURBO Pascal program by following the instruc-tions in your Reference Manual. Press Y when you are asked whether you would like messages included.

2. Press Wand answer MYNAME when asked for the name of your workfile. (Don't forget to press RETURN after you have typed in the program's name.)

3. Press E to get your TURBO Pascal editor going.

4. Type in the following program, just as it is written here. Don't forget to put in everything, including all punctuation marks and spaces. If you make a mistake, you can use your <Del>

key (orwhateverkeyyou have defined during TURBO Pascal terminal installation) to backspace and erase the characters you've typed.

program const

TotalTimes = 20;

var Name

NumberOiTimes begin

MyName;

String[ 25];

Integer;

Write( 'What is your name, please: ');

ReadlnCName);

ClrScr;

for NumberOiTimes := 1 to TotalTimes do

begin

end.

Writeln('Your name is ',Name);

end;

5. When you have finished typing in the program, press your CONTROL key and hold it down while you press K, then let both keys up and press D.

6. Press S to save the program you just typed in. This way you will have it later, if you want it.

7. Press R to compile the program (don't worry what that means for now) and to run it. You will see a message atthe bottom of your screen which you can also ignore for now.

In a moment, the program will run itself.So, just what did this program do?

If you typed it in correctly, and then typed your name correctly when it asked you for it, the program told you your name 20 times.

If you did not type it in c'orrectly, or if you did not type your name correctly, all the program gave you was garbage (if anything at all). Remember what I said about "Garbage In/Garbage Out?" (If you did get garbage, you may want to go back and compare what you typed into your computer with the program here in the book, and then try again. If you made a mistake and haven't yet learned the editing commands, it might be easier to retype the entire program at this time, using a new file name.)

Now let's look at the different parts of the program and talk for a moment about each. We will go into more detail about each in a few pages. For now, just try to get a sense of what is going on.

The program, called "MyName", has three main parts:

First: the place where you tell the compiler the name of the program.

programMyName;

The compiler uses this information to know where all the information it needs begins. It is the same as when you want to give a friend some instructions and you say, "This is where you start." We call this the Program Header.

Second: the definition statements:

ccmst

TotalTimes = 20;

var Name

NumberOfI'imes

striDg[ 25];

Integer;

The compiler uses the definition statements as tools when it begins to do what you want it to.

const is short for constant, the name of a number which will not change while the program is running. Since the number stays constant, we call it a constant-get it?

var is short for variable. Like its name, a variable can contain just about anything, for instance a name, a number, or something you make up.

Third: the program statements themselves:

begin

Write('What is your name, please: ')j Readln(Name )j

Cl.Iecrj

for NumberOfI'imes := 1 to TotaJ.Times do begin

eDd.

Write1n('Your name is ' ~ame)j end;

The program statements tell the compiler specific steps the computer must take to accomplish its assigned tasks.

An English narrative of this program would go something like this:

1. Start here

2. Ask "What is your name, please?"

3. Read the answer.

4. Erase the computer's screen.

5. Start a process where you write "Your name is" and the answer you read before (in step 3) twenty times, then stop the process.

6. Finish, end, quit, stop, fini.

By the way did you notice that every specific idea, or statement, ends with a semicolon (;)?This is similar to the way we speak with each other, in sentences, I mean. We express our ideas, each in turn, in sentences; Pascal does the same in "statements". Weend our sentences with periods; we end our Pascal statements with semicolons.

And yes, I see that begin, and const, and var don't have semicolons. This is an idiosyncrasy of how the compiler operates.

Now let's look at the process of programming, itself, a little more closely in the next chapter.

4. PROGRAMMING IS MORE THAN