Difference between revisions of "Basic Pascal Tutorial/Chapter 4/Functions/ja"

From Free Pascal wiki
Jump to navigationJump to search
Line 22: Line 22:
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
これはダメである。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.
+
これはやってはいけないことである。期待する値 3 を返す代わりに、無限の再帰ループがはじまってしまう。関数名が関数名を呼んでいる関数名を呼び出し、その関数名が関数名を呼び出して・・・などなど。
  
 
The return value is set by assigning a value to the function identifier.
 
The return value is set by assigning a value to the function identifier.

Revision as of 10:49, 19 August 2015

Template:Functions/ja

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

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

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

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

a := Name (5) + 3;

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

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

これはやってはいけないことである。期待する値 3 を返す代わりに、無限の再帰ループがはじまってしまう。関数名が関数名を呼んでいる関数名を呼び出し、その関数名が関数名を呼び出して・・・などなど。

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