Whi does while loop not work
Hi, I have a simple loop but get always an void and no result in x
let vnaam := ["a", "B", "C"];
let x := "";
for lst in vnaam do
let x := x + item(vnaam, lst)+ ", ";
void
end;
x
original I load al firstnames of the customers in vnaam. Result should be the firstnames of this customer seperated with ', '
2 replies
-
Oneliner:
concat((select Klanten).Voornaam)
Steven
-
While Steven's formula is the best way to solve your problem, it may still interest you to understand why your script does not give the expected result.
The reason is the "let" statement inside the loop. "let" creates a NEW variable "x", which is only visible inside the loop, "hiding" the variable "x" that has been created before entering the loop. After exiting the loop, this previous variable is visible again, and its value has not changed — it still contains "".
As for the appearance of the "void" statement: a "for" loop is not only a control structure, but also a function that returns a value. In your script, no value is available at the end of the loop, so Ninox inserts a "void" statement, that you can take as warning.
If you remove the "let" keyword inside the loop, and also the "item" function, since "lst" is already representing the value of each element in turn, you should get a result. But it will include a spurious ", " at the end, so Steven's formula is definitely the way to go.
Content aside
- 3 yrs agoLast active
- 2Replies
- 244Views