Loop Forever Technique
  (31-replies, RPG IV)
Post your reply | Return to Forum  Refresh | ascending | descending
Author: TFisher Return to Forum  Refresh 2010-07-30 21.57.11
Something else we use to do in our "forever" loop is check for program running 
in QRPLOBJ.  All our data queue programs where setup to automatically restart 
when they ended.  Using the SDS we checked to see if the program library name 
was QRPLOBJ:

  Dou %Shtdn or PgmLibrary = 'QRPLOBJ';
  .
  .
  Enddo;

Author: Ringer Return to Forum  Refresh 2010-07-30 16.44.04
> DoU %ShtDn() ;

yes, very nice.
Author: Sarge Return to Forum  Refresh 2010-07-30 15.59.38
Tag!!!!  you're it!

-sarge
Author: Ringer Return to Forum  Refresh 2010-07-30 15.49.59
Can we please GOTO a new subject, perhaps left handed indicators?
Author: DaleB Return to Forum  Refresh 2010-07-30 15.08.18
Let's face it, the problem is not, and never really was, use of GOTO and TAG.
The problem is with programmers using them in an uncontrolled fashion, leading
to illegible, unmaintanable code, yada, yada, yada. Structured constructs are
ultimately just camouflage, 'cause under the covers the compiler's still
generating branches and labels.

btw, I like the idea of DoU %SHTDN. I've used SHTDN or %SHTDN before, but never
for a "do forever".
Author: Ringer Return to Forum  Refresh 2010-07-30 14.58.23
Oh c'mon people, if you want an endless loop, use the RPG cycle...haha. Couldn't
resist.
Author: TFisher Return to Forum  Refresh 2010-07-30 14.37.57
Edman,
Sometimes good ol' fasion techniques are better (input primary files, 
subroutines, and yes, even GOTO in rare situations).  I defend these techniques 
often, but the truth is that I hate to use many of them and I have not used a 
GOTO in years.  The last time I did was to prevent paging in a very large 
program that serviced ATM and point of sale authorizations and performance was 
VERY critical.  I wouldn't hesitate to use GOTO again if the need presented 
itself.  I am not afraid to use old or new techniques, but from what I've seen 
the newer techniques do not perform as well as the older, yet I still use 
mostly newer techniques.
Author: Sarge Return to Forum  Refresh 2010-07-30 14.31.24
easy Tfish....its called planning ahead.

while some folks are creating PF/LF DDS, you have someone coding your TAG/GOTO 
sources.

TAG001 - TAG999

then have them create:

GOTO001 - GOTO999

now you not only have GOTO and TAGs, you have reduced the possibility of any 
naming convention of the TAG statement, so it is even less self documenting.

-sarge
Author: EdMan Return to Forum  Refresh 2010-07-30 13.50.25
Is that all Fish..... with your ol' fashion coding skills, I figured you would 
have AT LEAST a coupla 100 GOTO's
We know how scrweed up your logic is.... LOL.... D'oh

(Just joking my man... just joking.... Let me be the 1st to wish you a Happy 
Friday)
Author: TFisher Return to Forum  Refresh 2010-07-30 13.26.16
Sarge,
That will not work dude!  How will that allow me to have all 59 GOTOs that I 
need?   ;)
Author: Sarge Return to Forum  Refresh 2010-07-30 12.08.00
you could make the GOTO & TAG portion a /copy member.

/copy sourcefile/sourcetag
code
code
code
code
/copy sourcefile/sourcegoto

for the tag source:
c          top         tag

for the goto source:
c                      goto     top

then you could have a sourcegoto and sourcetag sourcemember for every single 
event.

-sarge
Author: CurtisB Return to Forum  Refresh 2010-07-30 11.19.53
clbirk:
Perfect! An unconditional loop forever!  What could be better?   :-)
Author: Ringer Return to Forum  Refresh 2010-07-30 09.59.03
> problem with RPG is I have to change TO to DOWNTO to perform a descending... 

Yep, agreed. I've thought that to be odd syntax too. Fortunately, I don't have
to use DOWNTO very much.
Author: clbirk Return to Forum  Refresh 2010-07-30 09.10.39
Well there is one more and hold your rotten tomatoes and don't throw them at 
me, I am only the message deliverer.

        Loop        Tag

    a bunch of code

            goto loop
Author: TFisher Return to Forum  Refresh 2010-07-30 06.44.54
I have used the %SHTDN (or SHTDN) technique for years.  When you think about 
it, it's really the best solution.
Author: patrik Return to Forum  Refresh 2010-07-30 05.02.44
usually i use this one   

      // "forever"
         dow '1';
           //do_something();
         enddo;

     

hth
Author: Basticar Return to Forum  Refresh 2010-07-29 17.07.21
My loop forevers are just plain boring in comparison to those I see here.  
I've always coded them like this:

          Dow      *In03 = *Off
          whole bunch of stuff
          Enddo

Lots of variations . . . but that's basically it >.<
/goes to her could'a, would'a, should'a corner.
Author: Bob Cozzi Return to Forum  Refresh 2010-07-29 17.05.21
Neil,

I couldn't agree more. I consistently do FOR i = 100 to 1 by -1 
Which course should work, but doesn't. :(

Author: Basticar Return to Forum  Refresh 2010-07-29 17.02.29
Yes, I can see that is a HUGE problem.  I'm just amazed it never occured to 
me before you pointed such lunacy out; now I'm just . . . UPSET!

;)
Author: neilrh Return to Forum  Refresh 2010-07-29 13.11.14
The problem with RPG is I have to change TO to DOWNTO to perform a descending 
loop count.  In all other languages I've used, the STEP/BY or whatever can be 
either positive or negative and will drive the TO/DOWNTO that RPG is incapable 
of with one generic statement.
Author: Ringer Return to Forum  Refresh 2010-07-29 13.05.41
neilster,

In RPG For, you step with BY...

For Count = 2 TO 10 By 2 ;
   ...even numbers...
EndFor ;

Chris
Author: neilrh Return to Forum  Refresh 2010-07-29 12.46.10
That is the big annoyance with FOR.  Almost any other language I've used 
includes some sort of STEP.  So I can just as easily do:
FOR x = 1 TO 10 STEP +1
FOR x = 10 TO 1 STEP -1

but more importantly I can:
FOR x = Start TO End STEP Inc
where Inc can be + or -.

The times I've had to code a procedure with bidirectional FOR, it's usually 
ended up with:
FOR x = Start TO End
  if I_want_to_do_this_backwards
    y = some_half_assed_equation_to_reverse_the_sequence_number
        (something along the lines of y = End - x + 1)
  else
    y = x
Author: Sarge Return to Forum  Refresh 2010-07-29 12.44.03
i like to write code that is easy to read for those who follow me, but my 
mischievous side comes out now and then when i do something like this:

/Free
 
 Dou 1 > 2;
  (something)
 EndDo;

or

define an indicator as a word such as CowsComeHome

 Dou CowsComeHome
  (something)
 EndDo;

i love it when someone looks at this and asks me "What does this piece of code 
do?"

-sarge
Author: TDaly Return to Forum  Refresh 2010-07-29 12.10.40
I never really cared for FOR.  The only thing it gives me is auto increment 
the counter.  BDD.  The TO/DOWNTO thing is just stupid.  It needs to work the 
way DOFOR works in CL.
Author: Bob Cozzi Return to Forum  Refresh 2010-07-29 10.31.22
Well, I don't think the point would be to really "do forever" just "do until I
issue a LEAVE" so the size shouldn't be an issue. But I tend to use 10i0 for
counter variables. This craps out at the 2.1 billion cycle mark. So If i hit
that, I deserve it.
Author: Ringer Return to Forum  Refresh 2010-07-29 10.15.13
That's real interesting Bob. Never knew that about For. 
Have to make the counter "big" like 20u0 so it doesn't get "The target for a
numeric operation is too small to hold the result"  ***CRASH***

For Count = *LoVal ;
   blah() ;
EndFor ;

Chris
Author: DougCMH Return to Forum  Refresh 2010-07-29 10.13.47
In the FOR example, what happens when X hits its upper limit?  Does it recycle, 
or does the program crash?
Author: TDaly Return to Forum  Refresh 2010-07-29 10.07.58
Hey just thought of this 

D Forever         c                   const('0') 

   DoU Forever;
     // something
   EndDo;

Always used DoW 1 = 1,  but I think I'll use this now
Author: Bob Cozzi Return to Forum  Refresh 2010-07-29 09.36.09
I like Doug's suggestion... never use %ShutDown but that's a great use for it.
Also, the advantage of the FOR example, is that X is auto-incremented by 1 each
pass--so you have a built-in counter.
Author: DougCMH Return to Forum  Refresh 2010-07-29 09.25.54
I prefer this - more control over closing down the program:

dou %shtdn();
Author: neilrh Return to Forum  Refresh 2010-07-29 09.04.24
A common one with a colleague of mine was: dou 1 = 0.
Author: Bob Cozzi Return to Forum  Refresh 2010-07-29 09.00.49
Just realized where we used to do something like this, for a "do forever":


      DOW   1 = 1;
      ...
         if (iWantToLeave);
           leave;
         endif;
      ENDDO;


We can do this, instead:


      FOR X;
        //  X is auto-incremented each pass
         if (iWantToLeave);
           leave;
         endif;
      endfor;


Not judging this code, just revealing it.
Your reply | top | Return to Forum | ascending | descending
      Name:
    
By pressing you agree to the
forum guidelines
      Note: Your message is limited to 3500 characters.