# Fl loop isn't resolving a statement that works outside a loop

I’m tidying up a formula, with what feels like a properly constricted fl loop.

So I’m condensing this.

\$

lv(“search_term”, “Change pod”)

\$\$

if(tc(count, ci(title, 0), “#search_term”) > 0, "Pod change "+tf(ci(start, 0)),

if(tc(count, ci(title, 1), “#search_term”) > 0, "Pod change "+tf(ci(start, 1)),

if(tc(count, ci(title, 2), “#search_term”) > 0, "Pod change "+tf(ci(start, 2)),

if(tc(count, ci(title, 3), “#search_term”) > 0, "Pod change "+tf(ci(start, 3)),

if(tc(count, ci(title, 4), “#search_term”) > 0, "Pod change "+tf(ci(start, 4)),

if(tc(count, ci(title, 5), “#search_term”) > 0, "Pod change "+tf(ci(start, 5)),

if(tc(count, ci(title, 6), “#search_term”) > 0, "Pod change "+tf(ci(start, 6)),

if(tc(count, ci(title, 7), “#search_term”) > 0, "Pod change "+tf(ci(start, 7)),

if(tc(count, ci(title, 8), “#search_term”) > 0, "Pod change "+tf(ci(start, 8)),

if(tc(count, ci(title, 9), “#search_term”) > 0, "Pod change "+tf(ci(start, 9)),

“No match”

)))))))))))

\$

Into this.

\$

lv(“search_term”, “Change pod”)

\$\$

fl(0, 9, “i+1”, if(tc(count, ci(title, i), “#search_term”) > 0, "Pod change "+tf(ci(start, i)),“No match”))

\$

But whereas the repeated statements work as expected, when replacing the count with i in the loop the statements fail with “No Match”

Locals set outside `fl()` don’t transfer inside. The loop also accepts a formula string to evaluate, so in your case the `if()` evaluates immediately and the result of it gets evaluated as the formula.

This should work:

``````fl(0, 9, "i+1",
tc(reg, "
if(ci(title, i) ~= '" + #search_term + "',
'Pod change ' + tf(ci(start, i)),
'No match'
),
',
tc(utf, 22)
)
")
``````

Notes:

• I’m using `'` as a placeholder for doublequotes (`"`) and replacing them with doublequotes using `tc(reg, ..., ', tc(utf, 22))`, where `tc(utf, 22)` returns `"`.
• I’m concatenating the content of the `search_term` local variable to the formula text instead of retrieving it in the loop.
• I replaced your `tc(count, ...) > 0` check with the “contains” operator (`~=`). As a bonus, this lets you use regex in your search term!

The formula text `fl()` gets to evaluate looks something like this:

``````if(
ci(title, i) ~= "Change pod",
"Pod change " + tf(ci(start, i)),
"No match"
)
``````
1 Like

That’s great, thanks so much. The syntax is starting to feel a lot more familiar, it’s the little catches and honestly I like to dig around finding a nice efficient way of doing things. This one had me stumped.

I’ll read up a bit more on operators, they sound useful.

Good luck! I’m gonna link the kode guide here, you might find it useful:

1 Like

@thetored Is this guide available as a PDF?

You can simply print the page as PDF. You may need to collapse the side menu first before you do this to only get the information on the main screen “printed”.

Thank you for the response. I will try that.

UPDATE : This is what I get when I print from Chrome on my device.

Have you tried doing this from your desktop/laptop? Try if the file below and see if this will work for you.

**credit to the owner of the guide.

1 Like

To get it to print properly, switch the theme to light, collapse the sidebar and dismiss the “Pick up where you left off” banner.

I’ve added a GitHub issue to include some print CSS to do this automatically in the future. The guide is available offline after you visit it once, and you can also install it like an app if you’d like, there’s a button in one of the top sections.

1 Like

Thanks for the great guide, man.

1 Like