[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New warning from compiler about loop variables



On 29/9/26 1:37 pm, Lee wrote:
On 9/28/26 6:47 PM, Brian G wrote:
I have discovered that many many of my loop variables are duplicated

I think there was a while where the code editor was adding a definition

when you used the variable.. must be because i don't think i used a dim in most cases of a loop

and there it was right at the top of the function...

Does anyone else remember this happening?


Not sure what you mean by, "a while", as if the editor stopped doing that. To my recollection, it has been doing that for some time now.

If you do:
  For x = 1 To 10
    ' do something
  Next
and 'x' has not been previously declared, the editor will add the declaration.

If you do:
  For x As Integer = 1 To 10
    ' do something
  Next
the editor will not add the declaration.


Yes, it has been a while but my recollection is that it is a bit simpler and a bit more complex.

Consider:

Dim X as Integer 'X is declared and has value of zero

For X = 6 to 123 ' X is set to 6 and
	do something
Next ' X is incremented
Print X ' Prints 123

For X as Integer = 1 to 12 ' X is declared as a*new Integer local to the loop*
	do something
Next
Print X ' Prints 123

I could be wrong. It's just what I recall.

b


Follow-Ups:
Re: New warning from compiler about loop variablesJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
References:
New warning from compiler about loop variablesBrian G <brian@xxxxxxxxxxxxxxxx>
Re: New warning from compiler about loop variablesLee <t.lee.davidson@xxxxxxxxx>