Loops 停止Rexx Do循环退出
由于某种原因,我的雷克斯环断了,我不知道为什么。我正在尝试通过ICCID(sim卡的识别号)搜索电话号码数据库,并提取电话号码。这是我的循环,有点简化:Loops 停止Rexx Do循环退出,loops,do-loops,rexx,oorexx,Loops,Do Loops,Rexx,Oorexx,由于某种原因,我的雷克斯环断了,我不知道为什么。我正在尝试通过ICCID(sim卡的识别号)搜索电话号码数据库,并提取电话号码。这是我的循环,有点简化: (t) is the tab hex code, ICCIDlist.txt contains a list of ICCIDs I'm trying to gather info on and phonenumberinfo.txt an exhaustive list of ICCIDs and Phone Numbers, looking
(t) is the tab hex code, ICCIDlist.txt contains a list of ICCIDs I'm trying to gather info on
and phonenumberinfo.txt an exhaustive list of ICCIDs and Phone Numbers, looking something like this:
89298374987 409-392-2434
89298765345 409-365-2132
89298334745 409-967-2863
----------------------------------------------
streamICCID=.stream~new('iccidList.txt')
lni = streamICCID~lines
DO i = 1 to lni
ICCID.i = streamICCID~linein(i)
END
soFile=.stream~new('phonenumberinfo.txt')
lno = soFile~lines
DO line = 1 to lno
lnInfo = soFile~linein(line)
lnFind = POS(ICCID.i,lnInfo)
IF lnFind==1 THEN DO
PARSE VAR lnInfo ICCID (t) ownNum.i
i = i + 1; ITERATE
END
ELSE ITERATE
END
DO n = 1 to i
SAY ownNum.n
END
它适用于第一个ICCID,但一旦从第一个ICCID中提取电话号码,它就会中断。我需要它继续,直到完成所有的ICCID。有人能帮我吗?你说得对,这只会在搜索一个ICCID(最后一个)时起作用。正如NicC所说,如果在
do行=…
循环之前放置一条Trace Intermediate
(或者只是Trace I
)指令,您可能会发现这一点。这样做会显示您正在进入该循环,并将i
设置为您读取的最后一个ICCID的编号,然后从那里开始计数(i=i+1;迭代)
在其他语言中,这种搜索问题通常通过两个嵌套循环来解决。加载第一个数据集后,您将迭代第二个数据集,对于每个记录,您将迭代整个第一个数据集,检查是否匹配。您没有这样做,而是手工编写内部循环,并且使用其索引变量(i
)用于两个不同且相互冲突的目的(迭代第一个数据集并创建输出数据集)
在Rexx中,我们不会这样做(尽管我们可以)。我们将通过将第一个数据集加载到关联数组中,然后在迭代第二个数据集时直接访问它来解决这个问题。这将一个N阶平方算法转换为N阶,以获得一个巨大的胜利
/* Load the ICCIDs into the "ICCID.*" associative array. The value of
each element we load is TRUE, and the value of anything else is FALSE.
*/
ICCIDlist. = 0 /* Set all the elements to FALSE */
streamICCID=.stream~new('iccidList.txt')
DO i = 1 to streamICCID~lines
item = streamICCID~linein(i)
ICCIDlist.item = 1 /* Set this element to TRUE */
END
/* Search the phone number file for ICCIDs we loaded above and record their presence. */
soFile=.stream~new('phonenumberinfo.txt')
lno = 0
DO line = 1 to soFile~lines
lnInfo = soFile~linein(line)
PARSE VAR lnInfo ICCID (t) phoneNumber
IF ICCIDlist.ICCID THEN DO /* If the ICCIDlist element is TRUE, it was in the first dataset */
lno = lno + 1
ownNum.lno = phoneNumber
END
END
/* Write out the phone numbers for the ICCIDs that we found in both datasets. */
DO n = 1 to lno
SAY ownNum.n
END
我建议您这样做:I=1到lni而不是I=1到lno,跟踪输出在哪里?你有跟踪吗?非常感谢Ross,它不仅有效,我理解它,而且更直接。欢迎来到StackOverflow!不要勉强接受最好的答案。