如何解决阻止Rexx Do Loop退出
由于某种原因,我的Rexx循环中断了,我也不知道为什么。我正在尝试通过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 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(最后一个)时才有效。正如NicC所说,如果您在Trace Intermediate
循环之前放一条Trace I
(或只是do line = ...
)指令,您可能会发现。这样做将显示您正在进入循环,其中i
设置为您读取的最后一个ICCID的编号,并且您从那里开始递增计数(i=i+1; ITERATE
)。
在其他语言中,这种搜索问题通常通过两个嵌套循环来解决。加载第一个数据集后,您将遍历第二个数据集,对于每个记录,您将遍历整个第一个数据集,检查是否匹配。您并没有这样做,而是在编写内部循环,并且将其索引变量(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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。