- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Nested for loop problem
Hi, 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<<NewColumn(colNames[col]);
for(row=1,row<=4,row++,
//write data into eachrow
);
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
You 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;
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
The 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 ) );
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
Thanks for reply. I tried above, code, it still add in the column "A" only, and column "B" "C" is not there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
You 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;
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Nested for loop problem
I strongly suggest you read or at least scan the Scripting Guide
Help==>Books==>Scripting Guide