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

Re: New warning from compiler about loop variables


Ah, of course. You are right, it should give a warning. Or not allow to
declare the variable again.


Jussi

On Tue, 29 Sep 2026, 16:48 brian, <brian@xxxxxxxxxxxxxxxx> wrote:

> The issue is if you declare a var and use it for something . And then by
> accident use and declare the same one in a loop. There was no error or
> warning you are left debugging ....
> Guilty as myself of that. Every other language would make that an error.
>
>
> On September 29, 2026 3:31:56 AM PDT, Jussi Lahtinen <
> jussi.lahtinen@xxxxxxxxx> wrote:
>
>>
>> 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 don't think so... At least the memory address do not change and thus
>> what would be the issue?
>>
>> Dim n As Integer
>> Print "initial; ";; VarPtr(n)
>>
>> For n As Integer = 0 To 0
>> Print "inside; ";; VarPtr(n)
>> Next
>>
>> Print "at the end; ";; VarPtr(n)
>>
>>
>> Jussi
>>
>>> ~~~Brian
>

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