Basic Pascal Tutorial/Chapter 4/Procedures/ja

This is an old revision of Basic Pascal Tutorial/Chapter 4/Procedures/ja, edited by Derakun at . The current revision is 108931.

Template:Procedures/ja

4A - 手続き (著者: Tao Yue, 状態: 原文のまま修正なし)

手続き(procedure)とはサブプログラムのことである。サブプログラムはプログラムの中の冗長さを減らす助けとなる。ループに入ってはいないが、繰り返し繰り返し実行される文はサブプログラムに収めることができることがよくある。

サブプログラムはまたトップダウンのデザインを容易にする。トップダウンのデザインとは最も一般的なものから最も特殊なものへとデザインするプログラムの取り組みのことである。たとえば、ある部屋から別な部屋へ行くトップダウンのデザインは次のようになる。

それから、それらは次のように細分化される。

単にドアのところへ行くこともさらに細分化できる。

もちろん、これはさらに細分化できる。どれほど心筋原線維に運動が必要か、どれほどアデノシン二燐酸がアデノシン三燐酸に発酵や酸素呼吸で変換されるべきか、などなど。これはあまりに細分化しすぎに思えるかもしれない。しかし、コンピュータ・プログラミングでは、これこそが実際にやらなくてはならないことなのである。コンピュータは一般的な命令文を理解できない。従って明確化しなくてはならないのである。

Main tasks should be contained in procedures, so in the main program, you don't have to worry about the details. This also makes for reusable code. You can just keep your procedures in one file and link that into your program.

A procedure has the same basic format as a program:

procedure Name;

const
  (* Constants *)

var
  (* Variables *)

begin
  (* Statements *)
end;

There is a semicolon (not a period) at the end.

To call the procedure from the main program, just use the name, like you would writeln.

Name;

Procedures are very often used to output data. It's that simple (until the next lesson, of course).

previous contents next