Sign in Join
Wiki copytemporary

Revision 1 of 1, by WikiArchive on 11-4-2026. The page as it is now.

Basic Pascal Tutorial/Chapter 4/Recursion/ja

4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし)

再帰 とは関数や手続きがある条件が満たされるまで自分自身を呼び出すことである。

数学における大文字の sigma (Σ) で示される合計関数は再帰的に書くことができる。

pascal
function Summation (num : integer) : integer;
begin
  if num = 1 
  then Summation := 1
  else Summation := Summation(num-1) + num
end;

3 で Summation を呼び出したとしよう。

pascal
a := Summation(3);

再帰は答えが定義されているある時点に達するまで後ろ向きに働く。それから、その定義を基にした他の定義を解きながら、その定義に対しては前向きに働く???(Recursion works backward until a given point is reached at which an answer is defined, and then works forward with that definition, solving the other definitions which rely upon that one.)。

再帰手続きや再帰関数はすべてその再帰が基準条件で止まるかテストするべきである。基準条件以外のすべての条件では再帰はどんどん深くなっていくだろう。もし、基準条件がないと、再帰は全く起きないか、無限状態のいずれかになるだろう。

上の例では、基準条件は if num = 1 である。

previous contents next

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Recursion/ja", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.