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



On Thu, 9 May 2002, Mark Adkins wrote:
>
> If there is a table of order detail which has an index on Order #, and UPC.
> Will these two pieces of code execute identically.
>
> 1.   MYORD#    CHAIN     ORDDTL    99
>      *IN99          DOWEQ*OFF
>                <SOMECODE>
>      MYORD#    READE     ORDDTL          99
>                ENDDO
>
> 2.   MYORD#    SETLL     ORDDTL
>      MYORD#    READE     ORDDTL          99
>      *IN99          DOWEQ*OFF
>                <SOMECODE>
>      MYORD#    READE     ORDDTL          99
>                ENDDO
>
> What if the index is not unique?  What if I set my pointer past the end of
> file before execution?

These two pieces of code will do the same thing.   If you added more to
it (such as using READ instead of READE, checking indicators on the SETLL,
etc, etc) then they wouldn't.

> Ever wonder why the 1st array element in most programming languages is 0?
> Or is it just me...
>

Because of the way arrays work at a lower level.   If you have an address
in memory that signifies the start of an array, and then you need to find
out the address of a given element in the array, you multiply the
array index times the size of each element to get an offset that you
can add to that first address.

With an array that starts with 0, this logic works.   With an array
that starts with 1, you have to first subtract 1 from the array index
before doing the calculation.

i.e. for an array starting with 0:

         element_addr = base_addr + (index * element_size)

     for an array starting with 1:

         element_addr = base_addr + ((index - 1) * element_size)

So, it's (slightly) easier to code an array that starts with 0.  Plus, the
code will run (slightly) faster.  If the person working with the array
would prefer to start with 1, they still can -- it just wastes one element
of the array.




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.