Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 4/Recursion/ja: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Basic Pascal Tutorial/Chapter 4/Recursion/ja

OldNewLine
1+4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし)
2+
3+**再帰** とは関数や手続きがある条件が満たされるまで自分自身を呼び出すことである。
4+
5+数学における大文字の *sigma* (Σ) で示される合計関数は再帰的に書くことができる。
6+
7+``` pascal
8+function Summation (num : integer) : integer;
9+begin
10+ if num = 1
11+ then Summation := 1
12+ else Summation := Summation(num-1) + num
13+end;
14+```
15+
16+`3` で `Summation` を呼び出したとしよう。
17+
18+``` pascal
19+a := Summation(3);
20+```
21+
22+- `Summation(3)` は `Summation(2) + 3` になる。
23+- `Summation(2)` は `Summation(1) + 2` になる、
24+- `1` になると、再帰は終了し、 `1` になる。
25+- `Summation(2)` は `1 + 2 = 3` になる。
26+- `Summation(3)` は `3 + 3 = 6` になる。
27+- `a` は `6` になる。
28+
29+再帰は答えが定義されているある時点に達するまで後ろ向きに働く。それから、その定義を基にした他の定義を解きながら、その定義に対しては前向きに働く???(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.)。
30+
31+再帰手続きや再帰関数はすべてその再帰が基準条件で止まるかテストするべきである。基準条件以外のすべての条件では再帰はどんどん深くなっていくだろう。もし、基準条件がないと、再帰は全く起きないか、無限状態のいずれかになるだろう。
32+
33+上の例では、基準条件は `if num = 1` である。
34+
35+| | | |
36+|----|----|----|
37+| [[Basic Pascal Tutorial/Chapter 4/Scope/ja|previous]] | [[Basic Pascal Tutorial/Contents/ja|contents]] | [[Basic Pascal Tutorial/Chapter 4/Forward Referencing/ja|next]] |
38+
39+---
40+*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](/wiki-contact).*

Back to history