Basic for loop to build a string (Newbie question)

As a newbie, I'm experimenting, one of the things I would like to do is built a "string" to inject variables into SQLite. If I "write" the string it works i.e. : ""topic":"INSERT INTO LiveData(c01,c02,c03,c04,c05,c06,c07,c08" etc..

Works fine.

So I would like to build that string. Anyone explain why:

var myString= "c1"
for (int I=1; I<200; I++) {
    myString=myString & ",c" & I;

Gives me an error "SyntaxError: Unexpected identifier (body:line 3)"

i.e. How do I use "For ... Next" within nodes.


I would say JS does not have a int definition and concatenating strings is done with + not &.

I would also crerate an array and join it as it deals with the ending comma issue.

let myArray = [];
for(let I=0; I<200; I++) {
myArray[I] = "c" + (I+1).toString().padStart(2, "0");
msg.topic = "INSERT INTO LiveData(" + myArray.join(",") + ") etc...";
return msg;

Mighty Cid :slight_smile:

I thank you kindly. Spot on. I fiddled with an array, and went to "Strings" because usually I find diag easier. But you solved my problems and enhanced my knowledge in one :slight_smile:



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