[Gambas-user] variable declaration everywhere ???

Jussi Lahtinen jussi.lahtinen at gmail.com
Wed Dec 12 00:38:17 CET 2018


Every time you redefine it, it is redefined. And depending on
implementation the variable could be valid only inside of the loop. If not,
then it is what it is defined.

For idx as integer = 0 to things.max
   dosomething(thing[idx])
next

Above idx is integer.

...
For idx = 0 to others.max
   dosomthingelse(others[idx])
next

Above idx is either undeclared or integer, depending on implementation.

...
For each idx as float in floatarray
   dowhatever(idx)

Above idx is float.


Jussi


On Wed, Dec 12, 2018 at 1:31 AM Bruce <adamnt42 at gmail.com> wrote:

> Well, I haven't tried it yet but a few things pop into my mind.
>
> Consider a method that has lots of use of "throw away" indexers/iterators,
> For idx as integer = 0 to things.max
>    dosomething(thing[idx])
> next
> ...
> For idx = 0 to others.max
>    dosomthingelse(others[idx])
> next
> ...
> For each idx as float in floatarray
>    dowhatever(idx)
>
> etc
> Is it going to redefine idx each time?
>
> b
>
> On 12/12/18 9:46 am, Benoît Minisini wrote:
> > Le 12/12/2018 à 00:11, Jussi Lahtinen a écrit :
> >> Why would it be harder to debug?
> >> David gave great example of it usage (pretty much only case where I
> >> use it) and I think it only makes code more readable and less scope
> >> for the variable.
> >>
> >>
> >> Jussi
> >>
> >
> > Because as soon as variables can be declared anywhere, people will start
> > to use that for writing ugly code. :-)
> >
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181212/fbbb303d/attachment-0001.html>


More information about the User mailing list