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

翻訳前ページへ


使用者 Defined 手続きs: part 1, Pascal Programming- plt1hf HOME - - - - - - - - - Other 構成要素 for programmers - - - - - - - - - Pascalite Tutorial (米)棚上げする/(英)提議する of Contents

Pascalite Programming

使用者 Defined 手続きs: Part 1

This 見解/翻訳/版 of this tutorial is 罰金 tuned for the open source FPC, aka 解放する/自由な Pascal. Most of what you read here should also 直接/まっすぐに 適用する if you are using Borland's Turbo Pascal (TP hereafter). It is also 利用できる for 解放する/自由な. Please send me an email with "(民事の)告訴s" if something doesn't work!

If you have a Pascalite, or the ソフトウェア emulation, then there's a separate tutorial for you, covering much of the ground as 現在のd here for the FPC/ TP (人が)群がる.


Pascal comes with a lot of "built in" words, e.g. Begin, End, Program, "If.. Then... Else, Repeat... Until, and LOTS more that you will 会合,会う in 未来 tutorials.

Nonetheless, in the course of many 事業/計画(する)s, you will find yourself feeling that その上の words would be useful. 恐れる not! You can "(不足などを)補う" words, and 追加する them to the language!

Our first example is going to look trivial, but please 耐える with me for a moment.

In an 早期に tutorial we had the に引き続いて program

program hi;
begin
 writeln('Hi');
 writeln('Bye');
end.

I'm going to change that わずかに, blending into it things which should be familiar. The に引き続いて 名簿(に載せる)/表(にあげる)ing will let you type almost anything, and then you'll get a "Hi" or a "Hello", depending on whether you entered 1 or more characters. And if you enter 999, the program will end. (Ordinarily, you would 誘発する 使用者s, so that they would have a better idea of what is going on, but we'll keep this "lean".)

program UserDefProcs;
var sTmp:string;

begin
repeat
  readln(sTmp);
  if length(sTmp)=1
    then writeln('Hi')//no ; here
    else writeln('Hello');
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.

I hope that is pretty transparent?

If you knew about 使用者-defined 手続きs, you could 達成する the same result with...

program UserDefProcs;
var sTmp:string;

   手続き SayHi;
     begin
     writeln('Hi');
     end;

   手続き SayHello;
     begin
     writeln('Hello');
     end;

begin //main

repeat
  readln(sTmp);
  if length(sTmp)=1
    then SayHi//no ; here
    else SayHello;
until sTmp='999';

writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.

At first ちらりと見ること, this might not seem an 改良.... but once you know your way around the basic structure, it isn't bad, and as your programs become more sophisticated, the breaking up of the program into manageable chunks becomes 必須の. So.... WHAT IS that "basic structure" you need to know your way around?



The main part of the program is at the end. It runs from the very last "end" in the program, the one with a period (十分な stop) after it, 支援する to the "begin" that is the partner of that end. (That's the extent of the main part of the program. It is 遂行する/発効させるd from the "begin" downwards, of course.) It is やめる usual to 示す the 関連した "begin" "//Main", to signify that it is the start of the main 封鎖する of code. In this 事例/患者, it is the に引き続いて....
begin //main

repeat
  readln(sTmp);
  if length(sTmp)=1
    then SayHi//no ; here
    else SayHello;
until sTmp='999';

writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.

"SayHi" and "SayHello" are not 基準 Pascal words. They are words we have created ーするために do the 職業 we have in mind for this program. The 指名するs should tell us what they do. We can look at the 詳細(に述べる)s in the part of the program before the main part. It is a classic "divide and 征服する/打ち勝つ" 戦略.

Remember that you can 挿入する new lines and spaces whereever it helps to make something more (疑いを)晴らす. Notice how the indenting and blank lines help make the sections of the code more evident. The "then" and "else" which go with the "if" are 平易な to find. The "until" for the "repeat" is 平易な to find. the 鮮明度/定義s of the two words we made up (before "begin //main") stand out nicely... at least they will, when you get used to reading this stuff!

Let's alter the program so that a blank line and then a line with "===="s appears before each 令状 of "Hi" or "Hello". First we'll do it the dumb, obvious way.

program UserDefProcs;
var sTmp:string;

   手続き SayHi;
     begin
     writeln;
     writeln('===============');
     writeln('Hi');
     end;

   手続き SayHello;
     begin
     writeln;
     writeln('===============');
     writeln('Hello');
     end;

begin //main

repeat
  readln(sTmp);
  if length(sTmp)=1
    then SayHi//no ; here
    else SayHello;
until sTmp='999';

writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.



The に引き続いて illustrates that you can even use words you've made up in words you've made up!

program UserDefProcs;
var sTmp:string;

   手続き separator;
   begin
      writeln;
      writeln('===============');
   end;

   手続き SayHi;
     begin
     separator;
     writeln('Hi');
     end;

   手続き SayHello;
     begin
     separator;
     writeln('Hello');
     end;

begin //main

repeat
  readln(sTmp);
  if length(sTmp)=1
    then SayHi//no ; here
    else SayHello;
until sTmp='999';

writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.

The only 制限 is that the "手続き separator begin.. end" stuff must appear BEFORE any place you try to use your new word (proper 称する,呼ぶ/期間/用語 for "your new word": 使用者 Defined 手続き). Even in this "trivial" example of the technique, I think you can see an advantage: It saves you typing out the two parts of the "Separator" twice. Half the chance for typos. If you do make a typo, at least the program will run 終始一貫して, with the same "Separator" between "Hi"s and "Hello"s. And a big advantage: If you want to make a change... say use "***" instead of "===", you can... without having to go through the program, and make the same change in several places. Within the 鮮明度/定義s of SayHi and SayHello, instead of the longwinded....

     writeln;
     writeln('===============');

... we now just have...

     separator;

There's more to using 手続きs than you might 心配する from this 簡潔な/要約する and 限られた/立憲的な introduction. They are important because they 簡単にする keeping a 事業/計画(する) under 支配(する)/統制する. We'll 調査する them その上の in 未来 tutorials.

Here's the link, if you are ready to return to the 索引 of Pascal tutorials for another one!



Please also 公式文書,認める that I have two other 場所/位置s, and that the に引き続いて search will not 含む them. They have their own search buttons.

My Sheepdog Guides 場所/位置.
My Arunet 場所/位置.

Go to the 場所/位置s above, and use their search buttons if you want to search them.
To search this 場所/位置....

Search this 場所/位置 or the web 力/強力にするd by FreeFind

場所/位置 search Web search
The search engine 単に looks for the words you type, so....
*    (一定の)期間 them 適切に.
*    Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....

You can also search this 場所/位置 without using forms.
広告 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.


Want a 場所/位置 hosted, or email? You can also help me if you 調印する up 経由で this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their 顧客s. The Google advertisers 支払う/賃金 me. I know nothing about them or their services, of course.)



Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Also, I have some of my pages' traffic 監視するd for me by eXTReMe tracker. They 申し込む/申し出 a 解放する/自由な tracker. If you want to try one, check out their 場所/位置. Why do I について言及する the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or 令状 this page's editor, Tom Boyd

....... P a g e . . . E n d s .....