Recursion

Gleam doesn't have loops, instead iteration is done through recursion, that is through top-level functions calling themselves with different arguments.

Gleam にはループがありません。その代わり、反復は再帰、つまり異なる引数で自分自身を呼び出すトップレベル関数によって行われます。

A recursive function needs to have at least one base case and at least one recursive case. A base case returns a value without calling the function again. A recursive case calls the function again with different inputs, looping again.

再帰関数は、少なくとも 1 つの基本ケースと、少なくとも 1 つの再帰ケースを持つ必要があります。基本ケースは、関数を再度呼び出すことなく値を返します。再帰ケースは、異なる入力で関数を再度呼び出してループを繰り返します。

The Gleam standard library has functions for various common looping patterns, some of which will be introduced in later lessons, however for more complex loops manual recursion is often the clearest way to write it.

Gleam 標準ライブラリには、様々な一般的なループパターンに対応する関数が用意されています。

Recursion can seem daunting or unclear at first if you are more familiar with languages that have special looping features, but stick with it! With time it'll become just as familiar and comfortable as any other way of iterating.

特別なループ機能を持つ言語に慣れていると、最初は再帰が難しく感じられたり、曖昧に感じられたりするかもしれませんが、粘り強く取り組んでください!時間が経てば、他の反復方法と同じように慣れ親しむことができ、快適になるはずです。