?? pascal.txt
字號(hào):
::::::::: :::::::: ::::::::: ::::::::::
:+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+
+#++:++#+ +#++:++#++ +#++:++#: :#::+::#
+#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+#
######### ######## ### ### ###
http://blacksun.box.sk
____________________
__________________________I Topic: I_______________________
\ I Pascal programming I /
\ E-mail: I for newbies I Written by: /
> I I <
/devil_panther@hotmail.com I____________________I devil panther \
/___________________________> <__________________________\
Introduction.
1) The Basics.
1.1) Basic constraction of the program.
1.2) Variables and Definition types.
1.3) Basic commands.
1.4) Div and Mod.
1.5) If...Else.
1.6) Case.
1.7) Consts.
1.8) Random numbers.
1.9) GoToXY.
2) Loops.
2.1) For...to...do.
2.2) While...do.
2.3) Repeat...until.
3) Arrays.
3.1) Array's definition.
3.2) Using Arrays.
3.3) Using Arrays and Loops.
4) Strings.
4.1) What the heck Strings are?!
4.2) String definition.
4.2) Using basic String.
5) Procedures and Functions.
5.1) What the heck a Procedure is?!
5.2) Writing a Procedure.
5.3) Parameters' rules.
5.4) Writing a Procedure with Parameters passing.
5.5) Return Parameters in Procedure.
5.6) What the heck is a Function?!
5.7) Writing a Function, and returns it's value. +
5.8) The problem with Procedures/Functions, and the solution.
6) Uses...
6.1) What is a Uses file?!
6.2) Uses Crt.
6.3) Writing your own Uses File.
**) Final Words.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*) Introduction:
*****************
Hello people, I'm the Devil Panther, and I'll teach you newbie programmers out there, the most
simple language of the huge(well, it's not that huge...) programming world, and all you need is
a brain, so run to make an x-ray to check if your brain is inside your head and not on the floor
when it spilled out from you ear, so if you see some thing red on the floor, and it's hard to thing,
get the idea, IT'S YOUR BRAIN DOWN THERE and stop reading!!! :)
This tutorial is only to make you understand the basics of the Pascal language, and a little
of the advanced part programming like the use of your own written functions in a better way.
At the end of the tutorail you will find the best example ever, for a good Pascal program.
It's an old Card game I wrote once. It's not perfect but you can make it perfect!
I think you know this old cards game, called Black Jack (21)... The game have bugs, like cards
repeat them self, it's YOUR job to fix it! REMEMBER: I made those bugs at the program on
purpose and I use too many variables also on purpose, so it's your DRILL/JOB to fix the bugs
and minimize the use of the variables in the game!!! To me, fixing this the game is like 1 2 3...
but to you, lets just say that you'll spend a lot of your spare time to fix the game by making the
code more effective, but it'll payoff in the end, believe me, it always does.
And Remember this as well, "I didn't write this tutorial for myself, I wrote it for you" ;)
Just One Small Thing before you start, the text inside the { } at the middle of the code are
'Line Notes', it's explains to you the meaning of the command, and what it's does.
P.S: You can get a free Turbo Pascal compiler at the next URL:
http://www.geocities.com/dp_site/Archive2/pascal.zip
Or try and look at the: www.borland.com web-site, you decide!
NOW go, go my children(actually, you were my childer I would shoot you and then shoot
myself!) and learn the most simple programming language there is to learn, almost the most
simple!!!
NOTE: When I'm talking about a Command, I'm actually mean: Function or a Procedure...
But, by calling those functions/procedure: commands, will make it easier for you to understand. It's for your own good!!! :) Because you don't know what a function is, or what a procedure is and
what it's good for and all this crap, but don't worry about it, you will learn about it in this tutorial.
NOTE: Turbo Pascal's compiler isn't sensitive for caps (you know, the small chars, and the big
big chars), for example: you can write: "writeln", or "WRITELN", or even "WriTELn" it's all the
same to the Dos compilers, because Dos isn't sensitive for caps, and it's a Dos based
compiler, even if you run it in Windows OS, but if you'll use a Windows based Pascal compiler
(like Dev Pascal, by BloodShed), but if you still would like Windows based compiler, then go to:
www.bloodshed.net and download a Windows based Pascal Based.
Just take that in mind.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1) The Basics.
1.1) Basic constraction of the program:
*******************************************
First thing you need to know, is that every pascal program must have a name,
what do i mean... Every program will start with: program the_name;
the name can't start with a number or any special signs, but you can use the numers in the
middle, but no the signs. you can't put a space in the middle of the name only _ ,
and every command in pascal must end with ; and so as: program abc;
Look at the next basic skeleton of a pascal program:
program program_struction;
var
{ here will come the global variables, we will get to it later! }
begin { the Main begin without ; at the end }
{ you write your code here }
end. { end of the program! the end of the program must be with a full stop at the end }
Simple isn't it!? :)
1.2) Variables and Definition types:
**************************************
Remember the VAR part in the skeleton, now we will talk about it.
But first a varible is a TAG, which let you to keep info inside it... like a number or a letter.
Let say we need a varuble that can keep a number in it, what do we do, how do we write it!?
First you need to ask your self what kind of num do you need in the program...real number (3.26), or a integer number (3)... look:
program var_example;
VAR
a, c, e: integer;
b, d, f: real;
ch: char;
{ you can choose any name you like for the varibles, but not in the name of the functions
and commands }
begin { Main Begin }
...
end. { Main End }
And in the Math section, the only sign which is different is: /
and the + , - , * are the same!
You see: in "REAL" type variable you can use / , but in the integer you can use only 'div' !
Because the integer type variable can include inside it only an integer number, so the 'div'
action will do the / but the variable which will get the the action's result (if it's an integer),
will get only the number before the dot (.) !
So in conclusion: the integer type can't get into it a REAL type number or a variable!!!
But a REAL type variable can get into it an integer type number or an integer type variable!
The threes type was "CHAR", this means that the variable "ch" will get only letters and special signs!
( Every Char owns a special number, an ASCII char number form 1 to 255 (256), you can get the
full list of all the ASCII code easaly at the next URL:
http://members.tripod.com/~plangford/index.html
You can transfer this char into it's ascii code, and back the next way:
1. If you want to get the "letter", and you got the number of this letter
(the number is the ascii code), you will do the next:
ch:=chr(97); { "ch" must be "CHAR" type variable. }
{ the ascii code 97 is the char 'a' }
{ You can also put an integer variable in the "CHR( )" instead of the number
but the variable MUST be an integer type!!! }
2. To get the number of the specific char (letter) you can do the next:
a:=ord('b'); { The "a" 'can' be 'REAL', it won't be a mistake. But it's a bad programming
thinking, you see a real programmer MUST own a special LOGIC to program
right! }
{ You can use instead of 'b' in the ( ), a "CHAT" type variable! }
{ the ascii code of 'b' is 98, so after this command the value of "a" will be:
98 , simple, isn't it?!! }
There is a Boolean type too, but you don't need it for know, a lot type more are exist, in Pascal!
1.3) Basic commands:
************************
1.3.1)
Let us start from the most simple one: write('Devil Panther is cool!');
What will it do, you ask?! It will print the line in the ' ' on the screen.
But what will happen if you will do the next:
program printing_example;
begin { main begin, and as you can see we didn't put 'var', before the begin, because we didn't
need any variables for this example }
write('DP ');
write('is cool');
end. { main end }
It will print:
DP is cool
What will you do if you want the program to get one line down after the DP ?
program printing_exampe2;
begin { the main begin }
writeln('DP'); { when you use writeln it will get one line down after he printed the line }
write('is cool'); { but here it will stay at the same line after he printed! }
end. { the main end }
You can also print varibles on the screen as well:
program printing_example3;
var
a: integer; { the declaration of the variable 'a', as integer }
begin { the main begin }
a:= 5; { it will place 5 into the variable 'a', this is the way to place value into a varible }
{ the value must much the type of the variable, like the number 5 you may only enter
into an integer or a real type variable, you can't do it with a char type variable!!! }
{ when you put := after a variable, this means that the value you'll write after the :=
will enter into the variable and stay there, until you'll place into it some other value,
or the program will end }
writeln('the number is A is: ',a,' got it?');
end. { the main end }
1.3.2)
The Readln command is made so the user of the program could make an input to a variable!
look:
readln(a); { this will make an input in to the variable 'a', this means, that the user need to
type/enter a value, when the program will get to the 'readln' command }
1.4) Div and Mod:
******************
Let say we got a variable with a number inside it, let say 34:
program div_mod_example;
var
a, c: integer; { declaration of variables, from an integer type }
begin { the main begin }
a:=34;
{ and now we will do the next: }
c:=a div 10;
a:=a mod 10;
end. { the main end }
You probebly think: "What the hell is that???".
Well, the first command will dev it by 10. 34 / 10 = 3.4 , right?!
So in the first command "c" will get the left part, which is before the dot.
And in the second command "a" will get the right part, which is after the dot.
The variable 'c' has now the value of 3,
and,
the variable 'a' has now the value of 4.
We didn't use "a" first, because we still needed it in it's full size (34).
You see, you need a logical thinking for programming, not just learning commands and use them, you need to know how to use them in a right way, because without that you stuck!
1.5) If...Else:
************
Sometimes you need to check the variables, and comparing them you a value, or to another variable.
So, how do you do it, you ask. Simple, there is a simple check with 'if'.
For example, let say
...
a:=56;
{ and }
d:=45;
...
Let say you want to check if they're equal...
if (a=d) then { the condition, will come in the ( ) and after that will come: than }
Now, if you will use only one command after the if just write it down under the if check!
But if you got more than one... then you must put BEGIN under the if check, to write down
your code that you wish the program to do if the condition is right (activated), after you wrote
you code you must put END; (NOT with a full stop(.)!!! But with ;)
You can also check
if (a>d) then { this will check if "a" is bigger than "d", if it's it will activate the code
under the 'if' }
You can check if "a" is Bigger than "d", or equal!
if (a>=d) then
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -