[U2] RE: DO/WHILE vs IF THEN

2009-02-27 Thread Israel, John R.
If you might also want to play with putting the WHILE... line just before the 
REPEAT.  This would be dependent upon your actual program (might need to 
consider if the loop starts with a failed condition).  Your mileage may vary.

John Israel


-Original Message-
From: owner-u2-us...@listserver.u2ug.org 
[mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen
Sent: Friday, February 27, 2009 11:20 AM
To: Ardent
Subject: [U2] DO/WHILE vs IF THEN

OK Aside from programming styles

Is there any functional difference between

WHILE expression DOand IF NOT(expression) THEN EXIT
and
UNTIL expression DOand IF expression THEN EXIT


First I thought that the DO/WHILE would activate as soon as
the condition occurred and drop out of a loop, but that is not
the case, the condition has to be active AND control has to be
back at the WHILE statement.


Example:

0001: CTR=0
0002: LOOP
0003:   CTR=CTR+1
0004:   WHILE CTR4 DO
0005:   PRINT CTR
0006:   CTR=CTR+1
0007:   PRINT CTR
0008:   CTR=CTR+1
0009:   PRINT CTR
0010:   CTR=CTR+1
0011:   PRINT CTR
0012:   CTR=CTR+1
0013:   PRINT CTR
0014:   CTR=CTR+1
0015:   PRINT CTR
0016:   CTR=CTR+1
0017:   PRINT CTR
0018: REPEAT
0019: STOP
0020: END

My first thought was that once CTR = 5, the loop would end (at LINE 12) but it
didn't
until control was passed back to LINE 4, then it ended.
---
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/
---
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/


[U2] RE: DO/WHILE vs IF THEN

2009-02-27 Thread George Gallen
I hadn't really played much with RAID/VLIST, so I guess this is my springboard..

VLISTING the WHILE/DO vs IF THEN yielded some interesting results

WHILE/DO
3 6 : 1C2 vec_addCTR 1  = CTR
5 E : 10C nop
5 00010 : 0DC lt CTR 4  = $R0
5 00018 : 2DE testfw $R0 00084:
6 00020 : 130 printcrlf  CTR
7 00026 : 1C2 vec_addCTR 1  = CTR
8 0002E : 130 printcrlf  CTR
9 00034 : 1C2 vec_addCTR 1  = CTR

IF/THEN EXIT
3 6 : 1C2 vec_addCTR 1  = CTR
4 E : 0DC lt CTR 4  = $R0
4 00016 : 10E not$R0  = $R1
4 0001C : 2DE testfw $R1 0002C:
4 00024 : 0C2 jump   00090:
6 0002C : 130 printcrlf  CTR
7 00032 : 1C2 vec_addCTR 1  = CTR
8 0003A : 130 printcrlf  CTR

Seems the IF/THEN EXIT adds a few extra opcodes in, but in general it's
pretty much the same effect. So with large loops (many records) it might
slow the process down a couple seconds.

George

 -Original Message-
 From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-
 us...@listserver.u2ug.org] On Behalf Of George Gallen
 Sent: Friday, February 27, 2009 11:20 AM
 To: Ardent
 Subject: [U2] DO/WHILE vs IF THEN

 OK Aside from programming styles

 Is there any functional difference between

 WHILE expression DOand IF NOT(expression) THEN EXIT
 and
 UNTIL expression DOand IF expression THEN EXIT


 First I thought that the DO/WHILE would activate as soon as
 the condition occurred and drop out of a loop, but that is not
 the case, the condition has to be active AND control has to be
 back at the WHILE statement.


 Example:

 0001: CTR=0
 0002: LOOP
 0003:   CTR=CTR+1
 0004:   WHILE CTR4 DO
 0005:   PRINT CTR
 0006:   CTR=CTR+1
 0007:   PRINT CTR
 0008:   CTR=CTR+1
 0009:   PRINT CTR
 0010:   CTR=CTR+1
 0011:   PRINT CTR
 0012:   CTR=CTR+1
 0013:   PRINT CTR
 0014:   CTR=CTR+1
 0015:   PRINT CTR
 0016:   CTR=CTR+1
 0017:   PRINT CTR
 0018: REPEAT
 0019: STOP
 0020: END

 My first thought was that once CTR = 5, the loop would end (at LINE 12)
 but it
 didn't
 until control was passed back to LINE 4, then it ended.
 ---
 u2-users mailing list
 u2-users@listserver.u2ug.org
 To unsubscribe please visit http://listserver.u2ug.org/
---
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/