# Why iteration specification in \`for\` can't use the function with \<transacts\> effetct ?

**URL:** <https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [September 19, 2023, 10:36am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163 "2023-09-19T10:36:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [September 19, 2023, 10:36am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163/1 "2023-09-19T10:36:51Z")

</div>

The below code in the Verse Document can’t compile.

> **[For](https://dev.epicgames.com/documentation/en-us/uefn/for-in-verse#failure)**
>
> The for expression iterates over a bounded number of items and repeats the expressions in its code block the same number of times.

```auto
for(X := 1..5; S := IncrementSomeVariable(); X < 3):
    X

```

Because `IncrementSomeVariable()` is not failer expression.  
Even if `IncrementSomeVariable()` has \< transacts \>, the code can’t compile too.

Is this a misnomer of documents?  
But why?  
Why iteration specification in `for` can’t use the function with \< transacts \> effect ?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 19, 2023, 11:06am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163/2 "2023-09-19T11:06:19Z")

</div>

The `for filter` is like an `if` block, it calls inside a failure context.  
If the function does not `<transacts>` then you can’t call it inside a failure context, it will tell you that :

`This invocation calls a function that has the 'no_rollback' effect, which is not allowed by its context.(3512)`

You have to workaround it, as the roadmap says, the `no_rollback` effect is meant to be removed  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/0/01096f4f6529527f84f89fedbd0842a49676c48a.png)

Using a `<transacts>` specifier should work, it does on my compiler though :

```auto
IncrementSomeVariable()<transacts>:int= # Please don't return void because you're using the returned value to assign the variable S
    return 1

for(X := 1..5; S := IncrementSomeVariable(); X < 3):
    X

```

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [September 20, 2023, 1:55am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163/3 "2023-09-20T01:55:00Z")

</div>

Thanks a lot !  
Sorry, I misunderstood.

Yore code can compile.  
 ![0919_2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/9/c/d9c03bc3aabc0821a68f15899ad7696991bc7688.png)

This my wrong code couldn’t compile.

 ![0919_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/c/fbcabd4bf83ba4b43103b3d290060cb14e392381.png)

I wonder why my code can’t compile.  
But my first question was solved for you.  
thank you.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 20, 2023, 10:31am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163/4 "2023-09-20T10:31:51Z")

</div>

These are not the same code block, mine is

```auto
for(X := 1..5; S := IncrementSomeVariable(); X < 3):

```

Yours is

```auto
for(X := 1..5; IncrementSomeVariable(); X < 3):

```

The for filter is supposed to have failable methods in it, so you’ll need to add the `<decides>` specifier to it. As shown in the doc :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/b/57b05e573bf509a43caf5decb113c335195c90fd.png)

I think my method works because the compiler allows for variable assignment as an exception so that you can have multiple statements next to each other inside `if blocks / for filters`.

But you might be right, if the assignment works then a void call should work too. I guess they’ll fix this with the no\_rollback update 🤷

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [October 20, 2023, 10:32am UTC](https://forums.unrealengine.com/t/why-iteration-specification-in-for-cant-use-the-function-with-transacts-effetct/1303163/5 "2023-10-20T10:32:01Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
