循環遍歷列表您好,我有一個月份名稱列表,我想循環遍歷該列表,從特定月份開始,比如說六月(第 6 個月),然後向後追溯到一月。
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]),
);我認為我有基礎知識,但我的循環一直在無限循環中進行。我將感謝您關於如何修復它的建議。 是的,在某個時候循環必須回到 12 月,但這將是另一場戰鬥。
進階統計建模消費者與市場研究品質和工藝工程回覆:循環遍歷列表TX 和 ThuongLe 您好,非常感謝您的回答。 它們也是很好的教訓。 我喜歡 StartMonth 和 TargetMonth 的優雅。
回覆:循環遍歷列表這應該有效
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),
);回覆:循環遍歷列表這裡有兩種方法可以做到這一點......我冒昧地添加了根據您想要開始的月份名稱確定起始值的功能。兩個範例給出相同的結果
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]