嗨,我有一个月份名称列表,但我想循环遍历列表,从一个特定月份开始,比如说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]