Re: Yet Another Enhancement Suggestion

new topic     » goto parent     » topic index » view thread      » older message » newer message

I concur, in my for loops, I have found it useful to access the value once
the loop is done . . .

----- Original Message -----
From: "Derek Parnell" <ddparnell at bigpond.com>
To: "EUforum" <EUforum at topica.com>
Subject: Yet Another Enhancement Suggestion


>
> Hi Robert,
> please consider this idea for a later release.
>
> Proposal:
>     If the index variable in a FOR loop is
>     already declared, use that variable and
>     allow it's value to be inspected when
>     the loop ends.
>
> Reason:
>     When a loop has prematurely exited, the
>     program often needs to know where it was
>     up to when this happened. Currently, we
>     must either create extra variables to
>     detect this common requirement, or use
>     a WHILE loop and do the indexing manually.
>
> Examples:
>
> Currently this doesn't work...
>
>     for i = 1 to length(pFields) do
>       if ... then
>         exit
>       end if
>     end for
>     if i > ...
>
> because 'i' has no scope beyond the for-loop.
>
> This also fails...
>     integer i
>     for i = 1 to length(pFields) do
>        if ... then
>          exit
>        end if
>     end for
>     if i > ...
>
> because 'i' is redeclared.
>
> I would like to see the second example become legal usage. It would save a
> lot of silly extra variables and generally simplify code. Also, it would
not
> break existing code because it is currently illegal usage.
>
> Now we tend to do this...
>
>     integer j
>     j = 0
>     for i = 1 to length(pFields) do
>        if ... then
>          j = i
>          exit
>        end if
>     end for
>     if j > ...
>
> or do this...
>
>     integer i
>     i = 1
>     while i <= length(pFields) do
>        if ... then
>          exit
>        end if
>        i += 1
>     end while
>     if i > ...
>
> both are more error-prone than allowing access to the FOR loop's index
> variable after the loop.
>
> -----------
> cheers,
> Derek Parnell
> Senior Design Engineer
> Global Technology Australasia Ltd
> dparnell at glotec.com.au
>
> ---------------------
>
>
of
> this message you are hereby notified that any use, dissemination,
> distribution or reproduction of this message is prohibited. If you have
> received this message in error please notify the sender immediately. Any
> views expressed in this message are those of the individual sender and may
> not necessarily reflect the views of Global Technology Australasia
Limited.
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu