Nested for loop problemHi, I am testing a nested for loop.
col loop will create new columns
row loop will write in data for each row.
The inner row loop seems has problem, it created 1st col, but that is all.
====================
colNames=list();
colNames[1]="A";
colNames[2]="B";
colNames[3]="C";
dt = New Table("new");
Current Data Table(dt);
for (col=1,col<=3,col++,
dt<
for(row=1,row<=4,row++,
//write data into eachrow
);
);
Re: Nested for loop problemI strongly suggest you read or at least scan the Scripting Guide
Help==>Books==>Scripting Guide
Re: Nested for loop problemGreat. Thanks Jim. First project. Kind of difficult to get started.Re: Nested for loop problemYou need to open the JMP log so you will see the errors. I assumed the code you showed was psudo code, just showing the structure of how you wanted the code to work. In JSL, you can not have a For loop without any arguments. So I have adjusted the code I returned to you, so it will work
Names default to here(1);
colNames = List();
colNames[1] = "A";
colNames[2] = "B";
colNames[3] = "C";
dt = New Table( "new" );
Current Data Table( dt );
// Add Empty Rows to the Data Table
dt << Add Rows( 4 );
For( col = 1, col <= 3, col++,
dt << New Column( colNames[col] );
For( row = 1, row <= 4, row++,
// Or you could conditionally add rows here
// If( Col == 1, dt << Add Rows( 1 ) );
column(dt,ColNames[col])[row]=1;
);
);Re: Nested for loop problemHi, Jim
Thanks for reply. I tried above, code, it still add in the column "A" only, and column "B" "C" is not there.Re: Nested for loop problemThe issue is that in the flow of the script that you are using, you need to explicitly add rows to your data table, using the << Add Rows() message. See the code below for a couple of ways you could do it. Also, the documentation for this is at:
Help==>Scripting Index==>Data Table==>Data Table Rows==>Add Rows
Names default to here(1);
colNames = List();
colNames[1] = "A";
colNames[2] = "B";
colNames[3] = "C";
dt = New Table( "new" );
Current Data Table( dt );
// Add Empty Rows to the Data Table
dt << Add Rows( 4 );
For( col = 1, col <= 3, col++,
dt << New Column( colNames[col] );
For( row = 1, row <= 4, row++,
// Or you could conditionally add rows here
// If( Col == 1, dt << Add Rows( 1 ) );
);
);