Basic Pascal Tutorial/Chapter 4/Functions/ja

From Lazarus wiki
Revision as of 10:41, 19 August 2015 by Derakun (talk | contribs)
Jump to navigationJump to search

Template:Functions/ja

4C - 関数 (著者: Tao Yue, 状態: 原文のまま変更なし)

関数は手続きと同様の働きをする。しかし、関数はメインのプログラムに 自らの名前を通して常に単一の値を返す

関数名 (パラメータ・リスト) : 戻り値の型;

関数はメインのプログラムの中で式を利用することで呼び出される。

a := Name (5) + 3;

もし、関数が引数を持っていないのであれば、関数名を関数内の右側に使わないように注意しなくてはならない。 たとえば、

function Name : integer;
begin
  Name := 2;
  Name := Name + 1
end.

これはダメである。Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop. Name will call Name, which will call Name, which will call Name, etc.

The return value is set by assigning a value to the function identifier.

Name := 5;

It is generally bad programming form to make use of VAR parameters in functions -- functions should return only one value. You certainly don't want the sin function to change your pi radians to 0 radians because they're equivalent -- you just want the answer 0.

previous contents next