このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Pascal tutorial: Introduction. HOME     >    >    >     TUTORIALS TABLE OF CONTENTS

An introduction to Pascal for Basic (衆議院の)議長s

This has good (警察などへの)密告,告訴(状)

Please don't 解任する it because it isn't 十分な of graphics, scripts, cookies, etc!

Delphi supersite: vote here Please click here to help my Delphi tutorials 場所/位置 get publicity


You want to know a bit about Pascal- good! When you do, you can make much better 進歩 with Delphi, a 広大な/多数の/重要な 環境 for Windows programming. (一般に... not just database 使用/適用s.) When you know Pascal, you can turn out 広大な/多数の/重要な DOS 使用/適用s with 極小の 成果/努力.

'But I don't have a Pascal compiler' I hear you cry. Don't worry! There are freeware compilers... やめる good ones... or, 扱う/治療する yourself 権利, and buy Borland's Turbo Pascal. Lovely 環境 to work in.

Click here for (警察などへの)密告,告訴(状) on freeware compilers. (If the FREE Pascalite ソフトウェア doesn't 控訴 you... though I'd be 利益/興味d to know what you think is wrong with it. Click here for Pascalite (警察などへの)密告,告訴(状).)

BASIC:
10 PRINT "Hello Cyberspace"

PASCAL:
program demo1;
begin
writeln('Hello Cyberspace')
end.

公式文書,認める: ' instead of " to 始める,決める off a string.

The most wonderful thing (to me!) about Pascal is that it has a 高度に formal structure. Learning what that is, and the variations 利用できる on the 主題 is the 重要な to happy Pascal programming.

A notation that doesn't 減ずる to this text based medium is used to 述べる the structure. Other 言及/関連 構成要素s, 含むing the Delphi and Turbo Pascal help とじ込み/提出するs, make use of it. Master its 解釈/通訳 早期に, and you will go far. I will 試みる/企てる a 見本 in 'character graphics':

A pascal program is...
program NAME;-----------------------BLOCK-----------------------.
               \/              \/           \/         \/
                \ DECLARATION; /             \ ;BLOCK  /

You read these diagrams by に引き続いて the lines. The one above says that a very simple Pascal program, with no 宣言s and the simplest possible 封鎖する ( begin end ) consists of just...

program デモ; begin end.

It wouldn't do anything, but it would 収集する and run.
(In most 事例/患者s, you can start a new line or not whereever you see fit. If in 疑問: start one!)
The diagram also 許すs our

program demo1; begin writeln('hello') end.

because...
begin 'writeln('Hello') end
.... is a 封鎖する.


An incomplete 鮮明度/定義 of 封鎖する would be that it is the word 'begin' followed by a 声明 (e.g.'writeln('Hello')) followed by the word 'end'.

Now the fun begins.... If you have two 声明s, and 'glue' them together with a semicolon, that is also a 声明. Why is that fun? Because it means that the に引き続いて also 満足させるs the 支配するs for a 合法的 program:

program demo1
begin
writeln('Hello');
writeln('Goodbye')
end.

Those 半分-結腸s are going to take some remembering... but they are 価値(がある) it. In general: if in 疑問, put one in. I could have had one after the ('Goodbye')... it would have 'created' a 声明 made out of two obvious 声明s glued together and with a 'third' '声明', consisting of nothing (!) glued の上に the end. The extra semicolon does no 害(を与える). 行方不明の semicolons do! This, by the way, is probably the moment to を取り引きする a little 詳細(に述べる): At the end of the program, there IS meant to be a '.', as shown.

We'll come 支援する to the semicolon 問題/発行する in a moment.

BASIC
10 x=5
20 IF x=5 THEN PRINT "It is 5" ELSE PRINT "It is not"

Pascal
program demo3;
var x:byte;
begin
x:=5;
if x=5 then
   writeln('It is 5') (*no ; here*)
  else
   writeln(It isn''t');
writeln('So there.');
end.


Seems like a lot of code for something BASIC could do in two lines.. but it is 価値(がある) it! When you start 令状ing real 使用/適用s, the value of the extra 構成要素 begins to 現れる. (And the 総計費 becomes a small 割合 of the 一括.)

Working through what we have...

var is a reserved word, i.e. one which is built into the language, has a particular meaning, like PRINT in BASIC. It comes from VARiable. You can't use a variable in Pascal unless you have 以前 宣言するd it (said that you are going to), AND said what 'type' of data will be going in that variable. The word type is used in a very 明確な/細部 sense here. For now, the two types you need are byte and string. Byte type variables can 持つ/拘留する the integers 0 to 255 (inclusive). String type variables can 持つ/拘留する strings of characters. The var x:byte; line is a 宣言. You can have several, as the lines in the program syntax diagram 示す.

x:=5; Notice that when you want to say 'make the value 蓄える/店d in x 5', you use two characters : and = together as if they were one. The 声明 x:=5 makes the variable x 持つ/拘留する 5.

if x=5 then.... Here we see the equals 調印する again, but this time on its own, there is no 結腸 in 前線 of it. Here we are doing a 実験(する). We are comparing what is in x with 5.

In general, the if 声明 is as follows:

if CONDITION then BLOCK else BLOCK

The main place you do NOT put a semicolon is between the end of the then's 声明 and the word else. All of the above is part of a basic 声明, and putting a semicolon in would be like...

BASIC
10 PRINT "You cannot
20 just break things up in their middle"

Putting something between (* and *) makes a comment, something the compiler ignores. { and } work the same way. Good programs almost always have LOTS of comments in them just helping to 明らかにする what the programmer ーするつもりであるd or 要求するd. I always put a (*no ; here*) comment just in 前線 of an else. It saves time wasted 跡をつけるing 負かす/撃墜する why something won't work.

You don't have to have the 'else BLOCK' part, so the に引き続いて is okay:

program デモ;
var x:byte;
begin
x:=5;
if x=5 then writeln('It is 5');
end.

______________
We have already seen the var 宣言. Another important 宣言 has the general form....

手続き NAME;BLOCK

The に引き続いて will work, comments in a moment...
program demo5
var x:byte;

   手続き XWasFive;
   begin
     writeln('X was 5');
   end;

   手続き XWasNotFive;
   begin
     writeln('X was not 5');
   end;

begin (*main*)
x:=5;
if x=5 then XWasFive else XWasNotFive
writeln('So there.');
end.


First a 詳細(に述べる): The blank lines and indents mean nothing to the compiler, but they can be a big help to human readers.

Second: Important and not obvious: When the program runs, the first thing it does is put 5 in the variable x. In other words, it skips over the 手続き 宣言s to the 'main' begin. The program only does what is 宣言するd in the 手続き 宣言s if those 手続きs get called by some line in the program.

Third: Why use 手続きs? In the simple program above, the 手続きs (XWasFive and XWasNotFive) are overkill... but in real programming, it is enormously helpful to be able, as it were, to (不足などを)補う new words for the language. You can 診察する the program at a high level by looking at the main 封鎖する. The 詳細(に述べる)s of what should happen if, say, x 持つ/拘留するs 5, can be 蜂の巣d off into a separate 封鎖する to be 熟考する/考慮するd in 詳細(に述べる) only when necessary. And when it is necessary, there won't be other things 伴う/関わるd to distract you.

Fourth: 手続き 宣言s must come before any use of the 手続き. It takes a little getting used to, but it means the compiler can be 急速な/放蕩な.

_____________
This scratches the surface. I hope you 設立する it useful.

広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows pc) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.
Link to Tutorials main page
How to email or 令状 this page's editor, Tom Boyd


- - o - -