遍歷列表嗨,我有一個月份名稱列表,但我想循環遍歷列表,從一個特定月份開始,比如說6月(第6個月),然後倒退到1月。
MonthList ={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//total number of months
nMonths = N Items (MonthList);
//initialize list of selected months
ElevenMo = {};
For (i = 6, i <= 11, i -= 1,
If (i >= 1, Continue () );
nextMonth = MonthList[i];
Insert Into (ElevenMo, nextMonth[i]),
);我想我有基本知識,但是我的循環一直處於無限循環中。感謝您提出的修復建議。 是的,在某些時候循環必須回到十二月,但這將是另一場戰鬥。
腳本編寫回复:遍歷列表這裡有2種方法來實現此目的。......我自由地添加了從要開始的月份的名稱中確定起始值的功能。兩個示例給出相同的結果
Names Default To Here( 1 );
MonthList = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
//total number of months
nMonths = N Items( MonthList );
targetMonth = "June";
startMonth = contains( MonthList, targetMonth );
//initialize list of selected months
ElevenMo = {};
For( i = startMonth, i >= 1, i--,
Insert Into( ElevenMo, MonthList[i] );,
);
Names Default To Here( 1 );
MonthList = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
//total number of months
nMonths = N Items( MonthList );
targetMonth = "June";
startMonth = contains( MonthList, targetMonth );
ElevenMo = MonthList[1::startMonth]回复:遍歷列表這應該工作
MonthList ={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//total number of months
nMonths = N Items (MonthList);
//initialize list of selected months
ElevenMo = {};
For (i = 6, i > 0, i--,
nextMonth = MonthList[i];
Insert Into (ElevenMo, nextMonth),
);回复:遍歷列表您好TX和ThuongLe,非常感謝您的回答。 他們也是很好的教訓。 我喜歡StartMonth和TargetMonth的優雅。