× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: DOU/DOW for READ Loops (My final word)
  • From: Jim Langston <jlangston@xxxxxxxxxxxxxxxx>
  • Date: Thu, 20 Apr 2000 11:28:19 -0700
  • Organization: Conex Global Logistics Services, Inc.

Basically, there are two types of DO's... Do While and Do Until, no
matter how you code it.  You can code a DOW that actually acts as
a DOU and vice verse.  So, the only question becomes, which do
you use?

I use both, depending on what I am trying to do.  If I need to do somethign
at least once, I do a DOU, if I am not sure if I have to do it once or
not, I do a DOW.

For a read, we are not sure if we have to do it once or not, so we use
a DOW.  Simple.  The only question then is, how do you "prime" the
do loop?  For a DOW loop, the condition has to be tested first thing,
so before you even run the DOW you need to have the test condition
set up.  There are few ways to do this, read the record first before you
perform the DOW, set on a variable as TRUE to begin so it runs
it once, then you have to put a huge IF statement in the DO loop.. I
prefer not to use the If statment, so I prime the DOW loop by reading
the record outside the loop first, then reading again at the bottom.

In Pseudo code:

READ SomeRecord
DOW %Found()
   Loop logic goes here.
   READ SomeRecord
ENDDO

To me, this is the cleanest.  No If statements have to be coded, but
there is the added maintainance issue of having to maintain two reads
now and not just one.  I have been caught before having to modify the
read statement, and only modifying one of them then wondering why
my change didn't work.  So, if it seems reasonable, I will actually do
the READ in a subroutine.

C's format works best.

Do While (Read Something)
   Loop logic here
ENDDO

We need that in RPG I think.

Regards,

Jim Langston


+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.