嵌套for循環問題您好,我正在測試一個嵌套的 for 循環。
col 循環將創建新列
行循環將為每一行寫入數據。
內部行循環似乎有問題,它創建了第一列,但僅此而已。
====================
列名=列表();
colNames[1]="A";
colNames[2]="B";
colNames[3]="C";
dt = 新表("新");
當前數據表(dt);
對於 (col=1,col<=3,col++,
dt<
對於(行=1,行<=4,行++,
//向每一行寫入數據
);
);
Re: 嵌套for循環問題我強烈建議您閱讀或至少掃描腳本指南
幫助==>書籍==>腳本指南
Re: 嵌套for循環問題偉大的。 謝謝吉姆。 第一個項目。 有點難上手。Re: 嵌套for循環問題您需要打開 JMP 日誌才能看到錯誤。 我假設您顯示的代碼是偽代碼,只是顯示您希望代碼如何工作的結構。 在 JSL 中,不能有沒有任何參數的 For 循環。 所以我已經調整了我返回給你的代碼,所以它會起作用
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: 嵌套for循環問題嗨,吉姆
感謝您的回复。 我在上面試過,代碼,它仍然只在“A”列中添加,而“B”列和“C”列不存在。Re: 嵌套for循環問題問題在於,在您使用的腳本流中,您需要使用 << 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 ) );
);
);