Foreach loops on static arrays error message
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 6 02:46:20 PDT 2017
On Thursday, 6 July 2017 at 09:11:44 UTC, Ola Fosheim Grøstad
wrote:
> ubyte[256] data;
>
> if (data.length > 0) {
> ubyte i = 0;
> do {
> writeln(i);
> } while ((++i) != cast(ubyte)data.length);
> }
Here is another version that will work ok on CPUs that can issue
many instructions in parallel if there are no dependencies
between them as you avoid an explicit comparison on the counter
(zero tests tend be be free):
ubyte[N] data;
size_t _counter = data.length;
if( _counter !=0){
ubyte i = 0;
do {
writeln(i);
i++;
} while (--_counter);
}
More information about the Digitalmars-d
mailing list