Bill, well of course my code is much more complicated than my little example.  
I have lots of "if" blocks within my block of code.  And some of those "if" 
blocks will do a "GOTO GetCursor" to fetch the next row.   There is also a 
possibility that there could be a fatal error that would cause it to go to 
EndCursor, but I don't have one of those.     So do you think there's a memory 
leak when there's a "goto" within an "if"?  I know we've had many threads on 
this before.  It's well known that you do NOT do a GoTo within a while loop 
that takes you to a label outside the while loop, but I thought we were pretty 
safe when the goto is within an "if"

Karen

 

 

 

-----Original Message-----
From: Bill Downall <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Fri, Mar 21, 2014 8:32 am
Subject: [RBASE-L] - Re: Thanks to someone for the code!


Tony is right, that the IF/GOTO constructs can be dangerous, but in this case, 
Karen is using a "Structured GOTO" to get around limitations of WHILE loops. If 
you look at Label EndCursor, you will see that there is a GOTO GetCursor just 
before it. There is still only one way in the code to get to the WRITE 'I am 
done!' statement. IF/GOTO becomes dangerous and hard to maintain when you have 
multiple ways to get to a block of code.


Bill




On Fri, Mar 21, 2014 at 9:14 AM, Dennis McGrath <[email protected]> wrote:

Also note, RStyle recognized two special comments --indent and --outdent to 
make goto loops format in a readable structure.
It even enforces that they be paired.
As far as RStyle is concerned, they are part of the code structure.


DROP CURSOR C1
DECLARE C1 CURSOR FOR SELECT  ....... blah blah blah

OPEN C1

LABEL GetCursor
--indent

  FETCH C1 INTO ..... blah blah blah
  IF SQLCODE = 100 THEN
    GOTO EndCursor
  ENDIF
  -- do all your processing here
  GOTO GetCursor

--outdent

LABEL EndCursor
WRITE 'I AM DONE!'
RETURN




Dennis McGrath
Software Developer
QMI Security Solutions
1661 Glenlake Ave
Itasca IL 60143
630-980-8461
[email protected]
From: [email protected] [mailto:[email protected]] On Behalf Of Dennis McGrath
Sent: Friday, March 21, 2014 7:59 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Thanks to someone for the code!

Tony,

Large while loops tend to be difficult to maintain as it is very easy to write 
something that will crash the loop.

Also, I have had while loops that absolutely refused to trace making debugging 
impossible.

Using the GOTO loop method results in code that may run a little slower, but is 
easier to maintain and not as fragile.

I use while loops for small tasks that iterate a great many times, and are not 
likely to change over time.

Otherwise, my time is better spent writing code that is less time intensive to 
debug and maintain.

I’m sure there are those folks who will violently disagree with me, and that is 
OK too.


Dennis McGrath
Software Developer
QMI Security Solutions
1661 Glenlake Ave
Itasca IL 60143
630-980-8461
[email protected]
From: [email protected] [mailto:[email protected]] On Behalf Of Tony IJntema
Sent: Friday, March 21, 2014 6:40 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Thanks to someone for the code!

Karen,

Maybe not relevant, but why don’t you use the while-endwhile construction.
If statements are handy, but also a little dangerous
10 if statements in a program will result in 1024 paths through your program

Tony

DROP CURSOR c1
DECLARE c1 CURSOR FOR SELECT  ....... blah blah blah
OPEN c1
FETCH c1 INTO ..... blah blah blah
while SQLCODE <>  100 THEN
       -- do all your processing here

FETCH c1 INTO ..... blah blah blah
endwhile
WRITE 'I AM DONE!'

From: [email protected] [mailto:[email protected]] On Behalf Of Karen Tellef
Sent: donderdag 20 maart 2014 23:18
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Thanks to someone for the code!

Well then, I'm guessing it was either Dennis or Alastair!  Or both!

Karen



-----Original Message-----
From: Alastair Burr <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Thu, Mar 20, 2014 2:21 pm
Subject: [RBASE-L] - RE: Thanks to someone for the code!
And I, for one, have been using it for many of those years.
 
Cheers, Dennis,
Regards,
Alastair.
 
From: Dennis McGrath


Sent: Thursday, March 20, 2014 7:01 PM
To: RBASE-L Mailing List

Subject: [RBASE-L] - RE: Thanks to someone for the code!
 
Perhaps someone else shared that with you but I’m been preaching that style for 
mucho many years.
 
Dennis McGrath
Software Developer
QMI Security Solutions
1661 Glenlake Ave
Itasca IL 60143
630-980-8461
[email protected]

From: [email protected] [mailto:[email protected]] On Behalf Of Karen Tellef

Sent: Thursday, March 20, 2014 1:52 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Thanks to someone for the code!
 
Probably a year ago I asked for recommendations of how to use alternative code 
for a cursor that had to go through 50,000 rows of data, run hundreds of lines 
of code per record, and would periodically lock up.  I got a couple examples, 
and I picked this one as being the easiest to follow, the simplest and best of 
all, IT WORKS!   I forgot who gave it to me, but thank you!   And perhaps this 
will help someone else.

Karen

DROP CURSOR c1
DECLARE c1 CURSOR FOR SELECT  ....... blah blah blah
OPEN c1

LABEL GetCursor

FETCH c1 INTO ..... blah blah blah

IF SQLCODE = 100 THEN
  GOTO EndCursor 
ENDIF

-- do all your processing here

GOTO GetCursor


LABEL EndCursor
WRITE 'I AM DONE!'


RETURN





Reply via email to