Foreach problem
    Tim M 
    a at b.com
       
    Sat Jan 10 18:59:26 PST 2009
    
    
  
On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep  
<daniel.keep.lists at gmail.com> wrote:
>
>
> Tim M wrote:
>>  Why is this an error. Dmd wants to make sure that I declare a new  
>> variable in the foreach statement and not use an existing one?
>>  module test;
>>  void main()
>> {
>>     int i;
>>     int[] nums;
>>     foreach(i; nums)
>>     {
>>         //
>>     }
>> }
>>   dmd test.d
>>  test.d(7): Error: shadowing declaration test.main.i is deprecated
>
> Yes; as the error states, you're not allowed to define variables with  
> the same name as variables in an enclosing scope any more.
>
>    -- Daniel
Why does it still work for some objects?
    
    
More information about the Digitalmars-d-learn
mailing list