On May 02, 2007, at 14:21 UTC, Daniel Stenning wrote:

> One thing I don't really like is how the dim statement repeatedly
> initialises. In my opinion it should only do this once.
> 
> Try running the following code:
> 
> 
>   for i as integer = 0 to 5
>     dim j as integer
>     j =j+1
>   Next
> 
> Here j is local in scope within the loop and in MY opinion should
> only get initialised to zero ONCE, so j gets incremented.  In fact j
> will get reinitialised to zero each time around, which to me just
> doesn't seem right.

The current behavior seems right to me.  Dim creates a new variable;
and whenever a variable is created in REALbasic, it's initialized to
the default value.  When a variable goes out of scope, it is
deallocated and no longer has its value.  In the code above, it clearly
goes out of scope at the end of the indented line (after "j=j+1"), so I
would expect it to lose its value there.  The next time through the
loop, we create a new j, and I'd expect that to have a value of 0.

It'd be really messy semantics if creation and deallocation didn't work
the same way in a loop as they do elsewhere.

Also, FWIW, this behavior is the same as in other modern languages like
Java and C++.

Best,
- Joe

--
Joe Strout -- [EMAIL PROTECTED]
Strout Custom Solutions


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to