home *** CD-ROM | disk | FTP | other *** search
-
- Introduction to the TURBO Pascal Tutorial
-
-
- Assuming you know nothing at all about Pascal, and in
- fact, that you may know nothing about programming in
- general, we will begin to study Pascal. If you are already
- somewhat familiar with programming and especially Pascal,
- you will probably want to skip very quickly through the
- first few chapters. You should at least skim the first few
- chapters, and you should read the remainder of this
- introduction.
-
- A few comments are in order to get us started in the
- right direction. The sample programs included on the disks
- are designed to teach you the basics of Pascal and they do
- not include any clever or tricky code. Nearly all of the
- programs are really quite dumb as far as being useful
- programs, but all will teach one or more principles of
- Pascal. I have seen one tutorial that included a 12 page
- program as the first example. In fact there were only 2
- example programs in the entire tutorial, and it was
- impossible to glean the essentials of programming from that
- system. For this reason, I will completely bypass any long
- programs until the very end of this tutorial. In order to
- illustrate fundamental concepts used in Pascal programming,
- all programs will be very short and concise until we reach
- the last chapter.
-
- The last chapter has some rather large programs to
- illustrate to you how to write a large program. It would be
- a disservice to you to show you all of the constructs of
- Pascal and not show you how to put them together in a
- meaningful way to build a large program. After completing
- all of the fundamentals of Pascal, it will then be very easy
- for you to use the tools learned to build as large a program
- as you desire.
-
- Another problem I have noticed in example programs is
- the use of one word for all definitions. For example, a
- sort program is stored in a file called SORT, the program is
- named Sort, and various parts of the program are referred to
- as Sort1, Sort2, etc. This can be confusing since you have
- no idea if the program name must be the same as the
- filename, or if any of the other names were chosen to be the
- same because of some obscure rule not clearly documented.
- For this reason, the example programs use completely
- arbitrary names whenever the choice of a name adds nothing
- to the readability or clarity of a program. As an
- illustration of this, the first program is named Puppy_Dog.
- This adds nothing to the understanding of the program but
- does illustrate that the program name means nothing to the
- Pascal compiler concerning what the program does.
-
-
-
-
- Page 1
-
-
-
-
-
-
-
-
-
- Introduction to the TURBO Pascal Tutorial
-
-
- Due to the fundamental design of the Pascal language,
- certain words are "reserved" and can only be used for their
- defined purposes. These are listed in your TURBO Pascal
- reference manual (page 37 - version 3.0; page 196 - version
- 4.0). All of the sample programs in this tutorial are
- written with the reserved words in all lower-case letters,
- and the user variables in lower case with the first letter
- capitalized since this is becoming the accepted industry
- standard. Don't worry about what reserved words are yet,
- they will be completely defined later.
-
- WHAT IS A COMPILER?
-
- There are two primary methods used in running any
- computer program that is written in a readable form of
- English. The first method is an interpreter. An
- interpreter is a program that looks at each line of the
- "English" program, decides what the "English" on that line
- means, and does what it says to do. If one of the lines is
- executed repeatedly, it must be scanned and analyzed each
- time, greatly slowing down the solution of the problem at
- hand. A compiler, on the other hand, is a program that
- looks at each statement one time and converts it into a code
- that the computer understands directly. When the compiled
- program is actually run, the computer does not have to
- figure out what each statement means, it is already in a
- form that the computer can run directly, hence a much faster
- execution of the program.
-
- This tutorial is written especially for Borland
- International's TURBO Pascal compilers version 3.0 or
- version 4.0. These are very high quality compilers that can
- do nearly anything you will ask them to do since they are so
- flexible. The original intent of this tutorial was to write
- it in such a way that it would be completely generic and
- usable with any good Pascal compiler. The programmers at
- Borland included a great many nonstandard aids for the
- Pascal language and resulted in a very good product that has
- dominated the market for microcomputers. To completely omit
- all of the extensions would do those of you with the Borland
- compiler a real disservice, and to include the extensions
- would not allow other compilers to be used effectively with
- this tutorial.
-
- The decision was made to stay with the Borland
- extensions and make the tutorial very difficult to use with
- other compilers. TURBO Pascal is so inexpensive that it
- would be a wise decision to purchase a copy solely for the
- purpose of learning the Pascal programming language then
- moving to a larger compiler on a minicomputer or a mainframe
- using the accumulated knowledge to very quickly learn the
-
-
- Page 2
-
-
-
-
-
-
-
-
-
- Introduction to the TURBO Pascal Tutorial
-
-
- extensions provided by that particular compiler. At any
- rate, this tutorial will not teach you everything you will
- ever need to know about Pascal. It will, however, teach you
- the fundamentals and the terminology needed to progress on
- your own into more advanced topics of Pascal and programming
- in general. You will find that experience will be your best
- teacher.
-
- Some of the example files will only work properly with
- TURBO Pascal version 3.0 and some will only work properly
- with version 4.0, but most will work with either. It will
- be clearly indicated to you which files will work with each
- of the two versions of TURBO Pascal.
-
- WHAT ABOUT TURBO PASCAL VERSION 2.0?
-
- Most of the files will compile properly with TURBO
- Pascal version 2.0, but no warning will be given since that
- version has been superseded for so long. It will pay you to
- purchase a newer version because of the flexibility. If you
- choose not to however, this tutorial will work fine in most
- cases if you follow the instructions for TURBO Pascal
- version 3.0.
-
- PREPARATION FOR USE OF THIS TUTORIAL.
-
- Copy the example files onto your TURBO working disk and
- you are ready to begin, provided of course that you have
- already learned how to start the TURBO system and how to
- edit a Pascal file. Be sure you make a backup copy of the
- Pascal tutorial disks so you cannot accidentally lose all
- information on the distribution disks. If you are using
- TURBO Pascal version 3.0, you should read Chapter 1 of the
- reference manual to be ready to use this tutorial, and if
- you are using TURBO Pascal version 4.0, you should read
- parts of chapters 1, 2, & 11 of your reference manual. You
- should be familiar with use of the editor supplied with
- TURBO Pascal before beginning.
-
- If you are not using TURBO Pascal, you will still be
- able to compile and execute many of these Pascal files,
- since most of the examples use standard Pascal syntax.
- There will be some statements used which are unique to TURBO
- Pascal and will probably not work with your compiler. This
- will be especially true when you come to the chapter on
- standard input and output since this is where most compilers
- differ. Unfortunately, this is one of the most important
- aspects of any programming language, since it is required to
- get data into and out of the computer to do anything useful.
-
-
-
-
- Page 3
-
-
-
-
-
-
-
-
-
- Introduction to the TURBO Pascal Tutorial
-
-
- It is highly suggested that you do the programming
- exercises after you complete the study for each chapter.
- They are carefully selected to test your understanding of
- the material covered in that chapter. If you do not write,
- enter, debug, and run these programs, you will only be
- proficient at reading Pascal. If you do the exercises
- completely, you will have a good start at being a Pascal
- program writer.
-
- It should also be mentioned that this tutorial will not
- teach you everything you will ever need to know about
- Pascal. You will continue to learn new techniques as long
- as you continue to write programs. Experience is the best
- teacher here just as it is in any endeavor. This tutorial
- will teach you enough about Pascal that you should feel very
- comfortable as you search through the reference manual for
- some topic. You will also be able to read and understand
- any Pascal program you find in textbooks or magazines.
-
- When you are ready, I will meet you in Chapter 1.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Page 4
-