D
dbeavon
Guest
I have been always been wary of defining and initializing variables in the local scope of a loop. Does the following code bother anyone else? In my opinion it seems to imply that the variable named v_Init will revert itself to "X" on every iteration ... but that implied initialization doesn't actually occur. DEFINE VARIABLE v_Loop AS INTEGER NO-UNDO. DO v_Loop = 1 TO 100: DEFINE VARIABLE v_Init AS CHARACTER NO-UNDO INIT "X". IF v_Loop = 10 THEN v_Init = STRING(v_Loop). MESSAGE v_Loop v_Init. PAUSE. END. As it turns out, once v_Init becomes "10" it never goes back to "X" again. I suppose it is just a gotcha that ABL programmers must know about. I suspect that this variable, v_Init has the same scope as v_Loop but we are allowed to define it in the loop as a matter of convenience. However, the convenience comes at a price of not being totally certain how the code will actually execute. Thanks, David
Continue reading...
Continue reading...