× 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.



Maybe I'm being thick (it is Friday after all), but why the 'if %equal'?

This is how I code my reade loops:

/free
   Setll key format;
   Reade key format;
   Dow not %eof;
       Exsr Process;
       Reade key format;
   Enddo;
/end-free

Or am I missing something?

Peter Colpaert
iSeries Application Developer

Honda Europe NV
Langerbruggestraat 104
B-9000 GENT
Belgium
Peter.Colpaert@xxxxxxxxxxxx
Tel: +32 9 2501 334
Fax: +32 9 2501 231
----------
Yoda of Borg are we: Futile is resistance. Assimilate you, we will.
----------



James Rich <james@xxxxxxxxxxx>
Sent by: midrange-l-bounces@xxxxxxxxxxxx
21/11/2003 09:57
Please respond to
Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>


To
Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
cc

Subject
Re: Two  reade loops: which one preferred ?






On Fri, 21 Nov 2003, afvaiv wrote:

> Just for curiosity, some people will code it the #2 way, but WHY do MOST
> people seem to prefer #1 ?
>
> ----- Style #1 -------------------------------------------
> mykey setll record
> if %equal
> mykey reade record
> dow not %eof
> ... process ...
> mykey reade record
> enddo
> endif
>
> ----- Style #2 -------------------------------------------
>
> mykey setll record
> if %equal
> do *HIVAL
> mykey reade record
> if %eof leave
> ... process ...
> enddo
> endif

Here's my take on this that hopefully makes good sense.  Looking at the
typical C way:

while ((fscanf(outfile, "%c", &c))!=EOF)
{
   do stuff...
}

we notice that all the logic that determines when a loop is executed or
exited is in one place.  You can easily tell that the loop will be run
depending on fscanf() and will only exit when fscanf() reaches EOF.

RPG has more than one way to code in a similar way.  But I think the goal
should be to make it easily discernable what will cause the loop to
execute and what will cause it to exit.  Keep the logic that does that in
one place: at the top of the loop.  This makes it immediately obvious how
the loop is designed to work.  One way to keep that logic together is to
use Style #2 that you mention.

Style #1 does not keep the logic together and therefore does not make it
immediately obvious how the loop is designed to work.  For this reason I
feel that Style #1 is poor programming style and should be avoided.

James Rich





The information contained in this communication is confidential and may be 
legally privileged. It is intended solely for the use of the individual or the 
entity to whom it is addressed and others authorised to receive it. If you have 
received it by mistake, please let the sender know by e-mail reply and delete 
it from your system.
If you are not the intended recipient you are hereby notified that any 
disclosure, copying, distribution or taking any action in reliance of the 
contents of this information is strictly prohibited and may be unlawful.
Honda Europe NV is neither liable for the proper and complete transmission of 
the information contained in this communication nor for any delay in its 
receipt.

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.