This is the preferred version. It's also a bit slower. The point is, you can GUARANTEE that LOP will decrement on every pass, and the loop will terminate.
With the other version, you need all sorts of extra code and crap to make sure you don't do what your original version is doing - ie counting from 1 to 8, and getting stuck on 4. If you kill the currently running infinite loop, then rerun it with a PRINT statement after the FOR, you will see that it successfully trims your string to 'THIS}IS}A TEST', but LOP is now 4, value 4 is the empty string, so LOP is decremented every pass, is stuck at 4, and will never reach the 8 needed to terminate the loop ... The decrement is less efficient at string handling. It is also far easier to code without screwing up - "there's only one way to do it (tm)", while the increment method has many ways of getting it wrong, and only one (complicated) way of getting it right. After you THINK you've got it right, try feeding it the string '}' :-) Cheers, Wol -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Olson Sent: 25 March 2004 12:57 To: 'U2 Users Discussion List' Subject: RE: Optimization ? ok... now what's quicker / preferred... PETE = 'THIS}IS }}}A TEST}}}' CRT TRIM( PETE , @VM ) REC = PETE MAX = DCOUNT( REC< 1 > , @VM ) FOR LOP = MAX TO 1 STEP -1 IF REC<1,LOP> = '' THEN REC=DELETE(REC,1,LOP) END NEXT LOP 300: CRT REC -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Anthony Youngman Sent: Thursday, March 25, 2004 7:47 AM To: U2 Users Discussion List Subject: RE: Optimisation ? After you decrement LOP, you need to decrement MAX. Otherwise the loop will be unable to get beyond 4. Think about it - as soon as you delete a null value, you are guaranteeing that "if null" will be true on your last pass, thereby decrementing LOP and requiring another pass, which will do the same, which will do the same ... That's why I ALWAYS do a "FOR I = MAX TO 1 STEP -1" style loop when coding this sort of stuff ... Bit slower, but far harder to mess up ... Cheers, Wol -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Olson Sent: 25 March 2004 12:41 To: 'U2 Users Discussion List' Subject: RE: Optimisation ? LOL... I can't get this to get out of the loop!!! the trim crt'ed pretty quick... neat! ----: L23 0001: PETE = 'THIS}IS }}}A TEST}}}' 0002: CRT TRIM( PETE , @VM ) 0003: REC = PETE 0004: MAX = DCOUNT( REC< 1 > , @VM ) 0005: FOR LOP=1 TO MAX 0006: IF REC<1,LOP> = '' THEN 0007: REC=DELETE(REC,1,LOP,0) 0008: IF LOP = MAX THEN GO 300 0009: LOP=LOP-1 0010: END 0011: NEXT LOP 0012: 300: 0013: CRT REC -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jonathan Leckie Sent: Thursday, March 25, 2004 7:29 AM To: [EMAIL PROTECTED] Subject: Optimisation ? I have the following piece of code : IF REC<1> � '' THEN MAX=DCOUNT(REC<1>,VM) FOR LOP=1 TO MAX IF REC<1,LOP> = '' THEN REC=DELETE(REC,1,LOP,0) IF LOP = MAX THEN GO 300 LOP=LOP-1 END NEXT LOP END I wonder could this simply be replaced with : IF REC<1> � '' THEN REC<1>=TRIM(REC<1>,@VM) GO 300 END Can anyone see any problems with using TRIM to remove trailing, repeated and initial value markers and therefore achieving the same effect without looping through each multi-value? This is on Unidata 3.3.2 incidentally. -- ************************************************************************ * This message has been scanned for viruses and dangerous content by * Blairs of Scotland MailScanner, and is believed to be clean. * * This email and any files transmitted with it are confidential and * intended solely for the use of the individual or entity to which they * are addressed. * * If you have received this email in error please notify us at Blairs * of Scotland via email at [EMAIL PROTECTED] ************************************************************************ -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users Notice of Confidentiality: The information included and/or attached in this electronic mail transmission may contain confidential or privileged information and is intended for the addressee. Any unauthorized disclosure, reproduction, distribution or the taking of action in reliance on the contents of the information is prohibited. If you believe that you have received the message in error, please notify the sender by reply transmission and delete the message without copying or disclosing it. -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users **************************************************************************** ******* This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system. Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333. **************************************************************************** ******* -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users Notice of Confidentiality: The information included and/or attached in this electronic mail transmission may contain confidential or privileged information and is intended for the addressee. Any unauthorized disclosure, reproduction, distribution or the taking of action in reliance on the contents of the information is prohibited. If you believe that you have received the message in error, please notify the sender by reply transmission and delete the message without copying or disclosing it. -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
