For Loop Arguments

Hi @frank ,

We all know the syntax of a For Loop function in Kustom preset, which is:

Syntax

fl(init, stop, increment, loop, [sep])

Arguments

  • init: First value of the i variable
  • stop: Condition value to meet in order to stop, eg 10
  • increment: Increment formula, eg i + 1
  • loop: Repeat formula or value, i will be replaced with the var
  • sep: Optional separator between elements

Now, the question is why do the increment and the loop have to be surrounded by a pair of double quotes (")?

I would suggest that the double quotes are not necessary or required, because it would be difficult to do when we want the loop to be a call to another function where one of its arguments is a string of text.

What do you think? Is it possible to make the double quotes in fl() not required?

Thank you.
:folded_hands::smiling_face:

1 Like

The reason is that “i” in increment is then replaced with the actual loop index, if you do not put quotes then kustom will evaluate the expression and it will become “i1” (join 2 strings). There is no way around this.

1 Like

Hmm… I see.

So, is there any workaround to be able to have the loop to call another function with one of its arguments is a string? Can we use a single quote (') for that?

Use quoteless strings, or tc(utf, 22) to concatenate a doublequote to your loop body string, or use ' or another placeholder and replace it using tc(reg):

$fl(0, 9, "i+1", tc(reg, "'$' + i", "'", tc(utf, 22)), " ")$

This example prepends $ to i, and $ has to be quoted - so I put it in ' and then replace those ' with " (which is returned from tc(utf, 22) as we don’t have a way to escape doublequotes).

I think the solution to this would be to add a way to escape doublequotes with for example a backslash so you could just do "\"$\" + i".

1 Like