简体   繁体   English

停止 Rexx Do Loop 退出

[英]Stop Rexx Do Loop from Exiting

For some reason my Rexx loop breaks and I don't know why.出于某种原因,我的 Rexx 循环中断了,我不知道为什么。 I'm trying to search a phone number database by ICCID (The identification number for sim cards) and pull the phone number.我正在尝试通过 ICCID(SIM 卡的识别号)搜索电话号码数据库并提取电话号码。 Here's the loop I have, a little simplified:这是我的循环,稍微简化了一点:

(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

It works for the first one, but as soon as it pulls a phone number from the first ICCID it breaks.它适用于第一个,但一旦从第一个 ICCID 中提取电话号码,它就会中断。 I need it to continue until it's done all of the ICCIDs.我需要它继续,直到完成所有 ICCID。 can anyone help me out?谁能帮我吗?

You're right, this will only work when searching for one ICCID - the last one.您说得对,这仅在搜索一个 ICCID(最后一个)时才有效。 As NicC says, you'd probably figure that out if you put a Trace Intermediate (or just Trace I ) instruction right before your do line = ... loop.正如 NicC 所说,如果您在do line = ...循环之前放置Trace Intermediate (或仅Trace I )指令,您可能会弄清楚这一点。 Doing so would show you that you're entering that loop with i set to the number of the last ICCID you read, and you're counting up from there ( i=i+1; ITERATE ).这样做会向您显示您正在进入该循环,其中i设置为您读取的最后一个 ICCID 的编号,并且您从那里开始计数( i=i+1; ITERATE )。

In other languages, this sort of searching problem is usually solved with two nested loops.在其他语言中,这种搜索问题通常用两个嵌套循环来解决。 After loading the first dataset, you iterate over the second, and for each record, you iterate over the entire first dataset, checking for a match.加载第一个数据集后,迭代第二个数据集,对于每条记录,迭代整个第一个数据集,检查是否匹配。 You're not doing that, you're hand-writing the inner loop, and you're using its index variable ( i ) for two different and conflicting purposes (iterating over the first dataset and creating the output dataset).您没有这样做,您正在手写内部循环,并且您将其索引变量 ( i ) 用于两个不同且相互冲突的目的(迭代第一个数据集并创建输出数据集)。

In Rexx, we wouldn't do that (athough we could).在 Rexx 中,我们不会这样做(尽管我们可以)。 We'd solve this instead by loading the first dataset into an associative array, and then directly accessing it while iterating over the second dataset.我们将通过将第一个数据集加载到关联数组中,然后在迭代第二个数据集的同时直接访问它来解决这个问题。 That turns an order N-squared algorithm into order N, for a big win.这将 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM