> For the complete documentation index, see [llms.txt](https://docs-embed.anyflow.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-embed.anyflow.jp/solution-editor/logic/loop.md).

# 繰り返し

繰り返しステップは、入力フィールドでリスト（例: 複数のkintoneレコード）を受け取り、リストの個数分だけステップを繰り返すものです。

ソリューションによって、リスト内のすべての項目に対して一連のアクションを実行する必要がある場合があります。\
このような場合に役立つのが、繰り返しステップです。

繰り返し内でインデントされたアクションは、リスト内の全項目に対して実行されます。

例えば以下のスクリーンショットのステップでは、step番号2のkintoneの`レコードを検索` アクションでヒットするレコードの一覧をリストで取得した後、step番号3で繰り返しステップを使いレコードの数だけstep番号4を繰り返しています。

<figure><img src="https://files.readme.io/bfb2362-for_each.png" alt=""><figcaption></figcaption></figure>

また、繰り返しステップの入力フィールドの`繰り返すリスト` の型はリストである必要があります。

変数ウィンドウでは、下図のようにリスト型のみが使用可能であることを認識することができます。（選択不可能な変数は選択できません。）

<figure><img src="https://files.readme.io/3967201-variable_window.png" alt=""><figcaption></figcaption></figure>

### **繰り返しモード**

Anyflowの繰り返しステップには、2つのモードが存在します。

1. アイテムごとに繰り返す
2. アイテムをまとめて繰り返す

<figure><img src="https://files.readme.io/a610008-repeat_mode.png" alt=""><figcaption></figcaption></figure>

通常は、1 の `アイテムごとに繰り返す` を使用してください。

ただ、時には上流のアプリやシステムがデータを送信する速度が、下流のアプリやシステムがデータを受信できる速度よりも速い場合があります。\
アイテムをまとめる個数を設定することで、このようなデータを処理するために`アイテムをまとめて繰り返す`機能を使用して解決することができます。

`アイテムをまとめて繰り返す` 機能を使うことで、\[1, 2, 3, 4, 5]のようなリストを、まとめる個数を2に設定した場合、`[1, 2]、[3, 4]、[5]` のようにまとめられて繰り返されるようになります。

5回の繰り返しが3回の繰り返しになるので、アクションの回数を減らすことが可能になります。

## **Breakステップ**

Breakステップは、繰り返しステップの中でのみ利用できるステップです。\
ifステップと併用することで、繰り返しステップを任意のタイミングで停止することが可能です。

**使い方**

繰り返しステップ内でステップの追加メニューを開くとBreakステップを選択することができます。

<figure><img src="https://files.readme.io/a55d641c6af672e156694c5f10163250354431d24b47631fcd716935b70151c3-_2025-02-14_17.26.33.png" alt=""><figcaption></figcaption></figure>

ifステップで繰り返しを停止する条件分岐を作成し配置することで、目的が達成された際に繰り返しステップの処理を終了することが可能です。

**例**

リストを取得し、要素ごとに繰り返しステップを行います。\
要素の値がエンドユーザー変数「入力値」と等しい場合はBreakステップにより繰り返し処理を終了し、等しくない場合は変数を更新し、リストの次の要素で処理を繰り返します。

<figure><img src="https://files.readme.io/7cef85d24f0f9248d83c351f60dc8685277d4b2bd8210fec2f999404dbeb477f-_2025-02-17_14.27.32.png" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-embed.anyflow.jp/solution-editor/logic/loop.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
