# Set a node loop like a While function

**URL:** https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376
**Category:** Help
**Tags:** workflow
**Created:** [February 25, 2022, 3:20pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376 "2022-02-25T15:20:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Jonathan\_Calderon](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@Jonathan\_Calderon](https://forums.losant.com/u/Jonathan_Calderon)
#### Post date: [February 25, 2022, 3:20pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/1 "2022-02-25T15:20:08Z")

</div>

Hello, im trying to do a loop like a function while. I need that the loop stop only when a attribute boolean is TRUE, but it is FALSE the loop don’t stop. Can help me? Thank

---

<div class="post-metadata">

### Author: ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)
#### Post date: [February 25, 2022, 4:03pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/2 "2022-02-25T16:03:28Z")

</div>

Hey @Jonathan_Calderon,

Welcome to the Losant forums, we’re happy to have you!

First, I’d really like to get a better idea of your use case. What solution is this while loop solving? Are you looking to execute certain business logic when an incoming device state attribute is `true`? How often is this attribute being updated and changing values?

Since it is not possible to implement a true `while` loop in Losant if you could provide more information about your use case, I’d be happy to help with a more appropriate implementation.

Thank you,  
Heath

---

<div class="post-metadata">

### Author: ![Jonathan\_Calderon](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@Jonathan\_Calderon](https://forums.losant.com/u/Jonathan_Calderon)
#### Post date: [February 25, 2022, 5:28pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/3 "2022-02-25T17:28:34Z")

</div>

Hi, I have an pagination API (Send the information in different pages). I don’t have the number of page that the API has. I think in a function "while "that stop when this API send a void object. This API send me information about device that i create inside the workflow. That’s it my problem. Thanks for the answer 🙂

---

<div class="post-metadata">

### Author: ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)
#### Post date: [February 25, 2022, 7:44pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/4 "2022-02-25T19:44:23Z")

</div>

Hey @Jonathan_Calderon,

Thanks for including that additional information.

If you are able to loop through the pages already, I would suggest that you use a [Conditional Node](https://docs.losant.com/workflows/logic/conditional/) to check for a `null` or `undefined` object or path on the payload.

This being said, I am assuming that you are making the HTTP request (with an [HTTP Node](https://docs.losant.com/workflows/data/http/)) and then using an item on the response body as the loop source for the loop node. If this is the case, the Loop node should stop looping once it has looped over the total number of items in the loop source. Once this is complete, your workflow will then move onto the next node (assuming there is one).

Is this the situation you are finding yourself in?

If you haven’t already, I would highly recommend that you check out [Losant University](https://university.losant.com/), specifically the module on the [Loop Node](https://www.youtube.com/watch?v=GTsmbDrQJQ0).

Please let me know if there is any other information I can provide, or if I am misunderstanding your issue.

Thank you,  
Heath

---

<div class="post-metadata">

### Author: ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)
#### Post date: [February 25, 2022, 8:01pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/5 "2022-02-25T20:01:17Z")

</div>

@Jonathan_Calderon,

There is another option to use a [Mutate Node](https://docs.losant.com/workflows/logic/mutate/) to put a large number (e.g. 10000, or a number guaranteed to be larger than the number of pages you have) on the payload and use it as the source for the loop node.

The idea here is that the number of loop iterations will be greater than the number of pages you receive from the API and the [Break Node](https://docs.losant.com/workflows/logic/loop/#break-node) will eventually end the Loop.

Please let me know if you need more detail.

Thank you,  
Heath

---

<div class="post-metadata">

### Author: ![Jonathan\_Calderon](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@Jonathan\_Calderon](https://forums.losant.com/u/Jonathan_Calderon)
#### Post date: [February 25, 2022, 8:19pm UTC](https://forums.losant.com/t/set-a-node-loop-like-a-while-function/4376/6 "2022-02-25T20:19:00Z")

</div>

Thank you Heath. I solved the problem with your information.
