Foreach loops on static arrays error message

Guillaume Chatelet via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 6 02:06:18 PDT 2017


On Thursday, 6 July 2017 at 09:00:47 UTC, Andrea Fontana wrote:
> On Thursday, 6 July 2017 at 08:26:42 UTC, Guillaume Chatelet 
> wrote:
>> From the programmer's point of view the original code makes 
>> sense.
>> A correct lowering would be:
>>
>>> ubyte[256] data;
>>> for(ubyte i = 0;;++i) {
>>>    ubyte x = data[i];
>>>    ...
>>>    if(i==255) break;
>>> }
>
> or:
>
> ubyte[256] data;
> foreach(ubyte i; 0..256) {
>   ubyte x = data[i];
> }
> 	

Yes. Much better. What's the rewrite in this case? Using a size_t 
internally and casting to ubyte?


More information about the Digitalmars-d mailing list